Skip to content

Migrate emails_disabled column to emails_enabled

What does this MR do and why?

This MR adds the migrations needed to take the emails_disabled column found in both the projects and the namespaces tables and switch to a positive connotation in being named emails_enabled.

Then, update places and tests throughout the codebase where the emails_disabled attribute is used, either changed or read, directly.

This is done with the end goal of matching the design found in #24733 (closed), specifically the request to switch to a positive connotation which includes the database column changing: #24733 (comment 954977953)

Screenshots or screen recordings

The default information in GDK doesn't have any values in emails_disabled to show that the switching of the content actually occurs in the migration of the data. So I've updated aa few of the rows to demonstrate the capability.

Capture of the emails_enabled :up migration on GDK's database
softhat@irune-gitlab:~/Work/TriLab/gitlab-development-kit/gitlab$ bin/rails db:migrate RAILS_ENV=development
main: == 20221116134507 AddProjectsEmailsEnabledColumn: migrating ===================
main: -- add_column(:projects, :emails_enabled, :boolean, {:default=>true, :null=>false})
main:    -> 0.0061s
main: == 20221116134507 AddProjectsEmailsEnabledColumn: migrated (0.0062s) ==========

main: == 20221116134539 AddNamespacesEmailsEnabledColumn: migrating =================
main: -- add_column(:namespaces, :emails_enabled, :boolean, {:default=>true, :null=>false})
main:    -> 0.0058s
main: == 20221116134539 AddNamespacesEmailsEnabledColumn: migrated (0.0059s) ========

main: == 20221116134611 AddNamespacesEmailsEnabledColumnData: migrating =============
main: -- transaction_open?()
main:    -> 0.0000s
main: -- exec_query("SELECT COUNT(*) AS count FROM \"namespaces\" WHERE NOT emails_disabled IS NULL")
main:    -> 0.0020s
main: -- exec_query("SELECT \"namespaces\".\"id\" FROM \"namespaces\" WHERE NOT emails_disabled IS NULL ORDER BY \"namespaces\".\"id\" ASC LIMIT 1")
main:    -> 0.0009s
main: -- exec_query("SELECT \"namespaces\".\"id\" FROM \"namespaces\" WHERE \"namespaces\".\"id\" >= 31 AND NOT emails_disabled IS NULL ORDER BY \"namespaces\".\"id\" ASC LIMIT 1 OFFSET 1")
main:    -> 0.0009s
main: -- transaction()
main: -- execute("UPDATE \"namespaces\" SET \"emails_enabled\" = NOT emails_disabled WHERE \"namespaces\".\"id\" >= 31 AND \"namespaces\".\"id\" < 74 AND NOT emails_disabled IS NULL")
main:    -> 0.0196s
main:    -> 0.0205s
main: -- exec_query("SELECT \"namespaces\".\"id\" FROM \"namespaces\" WHERE \"namespaces\".\"id\" >= 74 AND NOT emails_disabled IS NULL ORDER BY \"namespaces\".\"id\" ASC LIMIT 1 OFFSET 1")
main:    -> 0.0011s
main: -- transaction()
main: -- execute("UPDATE \"namespaces\" SET \"emails_enabled\" = NOT emails_disabled WHERE \"namespaces\".\"id\" >= 74 AND NOT emails_disabled IS NULL")
main:    -> 0.0015s
main:    -> 0.0022s
main: == 20221116134611 AddNamespacesEmailsEnabledColumnData: migrated (0.0287s) ====

main: == 20221116134633 AddProjectsEmailsEnabledColumnData: migrating ===============
main: -- transaction_open?()
main:    -> 0.0000s
main: -- exec_query("SELECT COUNT(*) AS count FROM \"projects\" WHERE NOT emails_disabled IS NULL")
main:    -> 0.0036s
main: -- exec_query("SELECT \"projects\".\"id\" FROM \"projects\" WHERE NOT emails_disabled IS NULL ORDER BY \"projects\".\"id\" ASC LIMIT 1")
main:    -> 0.0013s
main: -- exec_query("SELECT \"projects\".\"id\" FROM \"projects\" WHERE \"projects\".\"id\" >= 1 AND NOT emails_disabled IS NULL ORDER BY \"projects\".\"id\" ASC LIMIT 1 OFFSET 1")
main:    -> 0.0013s
main: -- transaction()
main: -- execute("UPDATE \"projects\" SET \"emails_enabled\" = NOT emails_disabled WHERE \"projects\".\"id\" >= 1 AND \"projects\".\"id\" < 6 AND NOT emails_disabled IS NULL")
main:    -> 0.0139s
main:    -> 0.0148s
main: -- exec_query("SELECT \"projects\".\"id\" FROM \"projects\" WHERE \"projects\".\"id\" >= 6 AND NOT emails_disabled IS NULL ORDER BY \"projects\".\"id\" ASC LIMIT 1 OFFSET 1")
main:    -> 0.0012s
main: -- transaction()
main: -- execute("UPDATE \"projects\" SET \"emails_enabled\" = NOT emails_disabled WHERE \"projects\".\"id\" >= 6 AND NOT emails_disabled IS NULL")
main:    -> 0.0017s
main:    -> 0.0024s
main: == 20221116134633 AddProjectsEmailsEnabledColumnData: migrated (0.0260s) ======
Capture of the emails_enabled 'down' migration on GDK's database
softhat@irune-gitlab:~/Work/TriLab/gitlab-development-kit/gitlab$ bin/rails db:migrate:down:main VERSION=20221116134633
main: == 20221116134633 AddProjectsEmailsEnabledColumnData: reverting ===============
main: == 20221116134633 AddProjectsEmailsEnabledColumnData: reverted (0.0006s) ======

softhat@irune-gitlab:~/Work/TriLab/gitlab-development-kit/gitlab$ bin/rails db:migrate:down:main VERSION=20221116134611
main: == 20221116134611 AddNamespacesEmailsEnabledColumnData: reverting =============
main: == 20221116134611 AddNamespacesEmailsEnabledColumnData: reverted (0.0005s) ====

softhat@irune-gitlab:~/Work/TriLab/gitlab-development-kit/gitlab$ bin/rails db:migrate:down:main VERSION=20221116134539
main: == 20221116134539 AddNamespacesEmailsEnabledColumn: reverting =================
main: -- remove_column(:namespaces, :emails_enabled, :boolean, {:default=>true, :null=>false})
main:    -> 0.0024s
main: == 20221116134539 AddNamespacesEmailsEnabledColumn: reverted (0.0110s) ========

softhat@irune-gitlab:~/Work/TriLab/gitlab-development-kit/gitlab$ bin/rails db:migrate:down:main VERSION=20221116134507
main: == 20221116134507 AddProjectsEmailsEnabledColumn: reverting ===================
main: -- remove_column(:projects, :emails_enabled, :boolean, {:default=>true, :null=>false})
main:    -> 0.0028s
main: == 20221116134507 AddProjectsEmailsEnabledColumn: reverted (0.0049s) ==========

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

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

Edited by Joe Snyder

Merge request reports