diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-26 21:39:32 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-26 21:39:32 +0200 |
commit | 33a0fd995bc00bc894243b0d7b2fda0367ae8b4c (patch) | |
tree | c9b6f440df66b141ec290ee37b53420531c6c135 /db | |
parent | b8c39649296049e402f8917b2b8a6123a302e672 (diff) | |
download | gitlab-ce-33a0fd995bc00bc894243b0d7b2fda0367ae8b4c.tar.gz |
Migrate build stage reference in a separate migration
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170526101042_migrate_pipeline_stages.rb | 8 | ||||
-rw-r--r-- | db/post_migrate/20170526185921_migrate_build_stage_reference.rb | 21 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 22 insertions, 9 deletions
diff --git a/db/post_migrate/20170526101042_migrate_pipeline_stages.rb b/db/post_migrate/20170526101042_migrate_pipeline_stages.rb index fdbefd59edf..05e095f07cb 100644 --- a/db/post_migrate/20170526101042_migrate_pipeline_stages.rb +++ b/db/post_migrate/20170526101042_migrate_pipeline_stages.rb @@ -15,14 +15,6 @@ class MigratePipelineStages < ActiveRecord::Migration GROUP BY project_id, commit_id, stage, stage_idx ORDER BY stage_idx SQL - - stage_id = Arel.sql('(SELECT id FROM ci_stages ' \ - 'WHERE ci_stages.pipeline_id = ci_builds.commit_id ' \ - 'AND ci_stages.name = ci_builds.stage)') - update_column_in_batches(:ci_builds, :stage_id, stage_id) - - # add_concurrent_foreign_key :ci_stages, :projects, column: :project_id, on_delete: :cascade - # add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade end def down diff --git a/db/post_migrate/20170526185921_migrate_build_stage_reference.rb b/db/post_migrate/20170526185921_migrate_build_stage_reference.rb new file mode 100644 index 00000000000..8f453b8cd82 --- /dev/null +++ b/db/post_migrate/20170526185921_migrate_build_stage_reference.rb @@ -0,0 +1,21 @@ +class MigrateBuildStageReference < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + disable_statement_timeout + + stage_id = Arel.sql('(SELECT id FROM ci_stages ' \ + 'WHERE ci_stages.pipeline_id = ci_builds.commit_id ' \ + 'AND ci_stages.name = ci_builds.stage)') + + update_column_in_batches(:ci_builds, :stage_id, stage_id) + end + + def down + disable_statement_timeout + + update_column_in_batches(:ci_builds, :stage_id, nil) + end +end diff --git a/db/schema.rb b/db/schema.rb index f1df8d6bd8c..87e16e2f69c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170526101042) do +ActiveRecord::Schema.define(version: 20170526185921) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |