summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-04-25 13:40:13 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-04-25 13:40:13 +0000
commit37b9a441c1b74c679419ecd6c9560ab4390898b9 (patch)
tree2fce001235b0ea3adb06bf1d37a6c21d5d336b6e /db/post_migrate
parentdf6a2d423ea4dac3484669f6f49c535b36288d5d (diff)
parent5beb4ddebfa23b288dc088c7175c2456d411f4f1 (diff)
downloadgitlab-ce-37b9a441c1b74c679419ecd6c9560ab4390898b9.tar.gz
Merge branch 'master' into 'backstage/gb/migrate-pipeline-stages-index'
# Conflicts: # db/schema.rb
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb b/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb
new file mode 100644
index 00000000000..3b0fdb3aeea
--- /dev/null
+++ b/db/post_migrate/20180409170809_populate_missing_project_ci_cd_settings.rb
@@ -0,0 +1,34 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class PopulateMissingProjectCiCdSettings < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ # MySQL does not support online upgrades, thus there can't be any missing
+ # rows.
+ return if Gitlab::Database.mysql?
+
+ # Projects created after the initial migration but before the code started
+ # using ProjectCiCdSetting won't have a corresponding row in
+ # project_ci_cd_settings, so let's fix that.
+ execute <<~SQL
+ INSERT INTO project_ci_cd_settings (project_id)
+ SELECT id
+ FROM projects
+ WHERE NOT EXISTS (
+ SELECT 1
+ FROM project_ci_cd_settings
+ WHERE project_ci_cd_settings.project_id = projects.id
+ )
+ SQL
+ end
+
+ def down
+ # There's nothing to revert for this migration.
+ end
+end