Skip to content

Change the default database value of project_view to 2

Abdul Wadood requested to merge 388393-project-view-default into master

What does this MR do and why?

While working on #388393 (closed) I found that the default value in the model (:files i.e. 2) differs from the default in the database (i.e. 0). The default value in the model was changed in this commit b3971d0f but the default database value wasn't changed.

This MR changes the default in the database to match the model's default value. See our database guidelines for changing the column default.

I have also verified the same from the production data:

gitlabhq_dblab=# select count(*) from users where project_view = 0;
 count
-------
  1524
(1 row)

gitlabhq_dblab=# select count(*) from users where project_view = 2;
  count
----------
 13820589
(1 row)

We only have 1.5k rows with 0 whereas 13M rows with 2. We would obviously have more rows with the default being used.

Migration output

up
bin/rails db:migrate
main: == [advisory_lock_connection] object_id: 223680, pg_backend_pid: 83446
main: == 20230707114012 ChangeProjectViewDefault: migrating =========================
main: -- change_column_default(:users, :project_view, {:from=>0, :to=>2})
main:    -> 0.1663s
main: == 20230707114012 ChangeProjectViewDefault: migrated (0.1752s) ================

main: == [advisory_lock_connection] object_id: 223680, pg_backend_pid: 83446
ci: == [advisory_lock_connection] object_id: 224040, pg_backend_pid: 83448
ci: == 20230707114012 ChangeProjectViewDefault: migrating =========================
ci: -- change_column_default(:users, :project_view, {:from=>0, :to=>2})
ci:    -> 0.0115s
ci: == 20230707114012 ChangeProjectViewDefault: migrated (0.0308s) ================
down
bin/rails db:rollback:ci && bin/rails db:rollback:main
ci: == [advisory_lock_connection] object_id: 223380, pg_backend_pid: 88332
ci: == 20230707114012 ChangeProjectViewDefault: reverting =========================
ci: -- change_column_default(:users, :project_view, {:from=>2, :to=>0})
ci:    -> 0.0977s
ci: == 20230707114012 ChangeProjectViewDefault: reverted (0.1145s) ================

ci: == [advisory_lock_connection] object_id: 223380, pg_backend_pid: 88332
main: == [advisory_lock_connection] object_id: 259480, pg_backend_pid: 88753
main: == 20230707114012 ChangeProjectViewDefault: reverting =========================
main: -- change_column_default(:users, :project_view, {:from=>2, :to=>0})
main:    -> 0.1599s
main: == 20230707114012 ChangeProjectViewDefault: reverted (0.1791s) ================

main: == [advisory_lock_connection] object_id: 259480, pg_backend_pid: 88753

Next step

Follow-up issue to remove the SafelyChangeColumnDefault concern in %16.3 #417531 (closed)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #388393 (closed)

Edited by Abdul Wadood

Merge request reports