diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-26 14:46:45 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-26 14:46:45 +0200 |
commit | 918ababba6fce694c61d54bb2ff6983a886f696a (patch) | |
tree | 1d502368d29711fb4c2fae814b4fb99bb8ca4bfe /db | |
parent | 0f9fbae78a51f7bf4df50d96060087e1cf903b05 (diff) | |
download | gitlab-ce-918ababba6fce694c61d54bb2ff6983a886f696a.tar.gz |
Add pipeline stages post deployment migration
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20170525132202_create_pipeline_stages.rb (renamed from db/migrate/20170525132202_migrate_pipeline_stages.rb) | 2 | ||||
-rw-r--r-- | db/post_migrate/20170526101042_migrate_pipeline_stages.rb | 43 | ||||
-rw-r--r-- | db/schema.rb | 5 |
3 files changed, 48 insertions, 2 deletions
diff --git a/db/migrate/20170525132202_migrate_pipeline_stages.rb b/db/migrate/20170525132202_create_pipeline_stages.rb index a9fe00ebf72..c562df27357 100644 --- a/db/migrate/20170525132202_migrate_pipeline_stages.rb +++ b/db/migrate/20170525132202_create_pipeline_stages.rb @@ -1,4 +1,4 @@ -class MigratePipelineStages < ActiveRecord::Migration +class CreatePipelineStages < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers DOWNTIME = false diff --git a/db/post_migrate/20170526101042_migrate_pipeline_stages.rb b/db/post_migrate/20170526101042_migrate_pipeline_stages.rb new file mode 100644 index 00000000000..12ad0db3a60 --- /dev/null +++ b/db/post_migrate/20170526101042_migrate_pipeline_stages.rb @@ -0,0 +1,43 @@ +class MigratePipelineStages < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + disable_statement_timeout + + execute <<-SQL.strip_heredoc + INSERT INTO ci_stages (project_id, pipeline_id, name) + SELECT project_id, commit_id, stage FROM ci_builds + WHERE stage IS NOT NULL + GROUP BY project_id, commit_id, stage, stage_idx + ORDER BY stage_idx + SQL + + add_concurrent_index(:ci_stages, [:pipeline_id, :name]) + + add_column(:ci_builds, :stage_id, :integer) + + 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 + execute('TRUNCATE TABLE ci_stages') + + if column_exists?(:ci_builds, :stage_id) + remove_column(:ci_builds, :stage_id) + end + + if index_exists?(:ci_stages, [:pipeline_id, :name]) + remove_index(:ci_stages, [:pipeline_id, :name]) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 581060f62fc..f1df8d6bd8c 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: 20170525132202) do +ActiveRecord::Schema.define(version: 20170526101042) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -233,6 +233,7 @@ ActiveRecord::Schema.define(version: 20170525132202) do t.string "coverage_regex" t.integer "auto_canceled_by_id" t.boolean "retried" + t.integer "stage_id" end add_index "ci_builds", ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree @@ -333,6 +334,8 @@ ActiveRecord::Schema.define(version: 20170525132202) do t.datetime "updated_at" end + add_index "ci_stages", ["pipeline_id", "name"], name: "index_ci_stages_on_pipeline_id_and_name", using: :btree + create_table "ci_trigger_requests", force: :cascade do |t| t.integer "trigger_id", null: false t.text "variables" |