diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-06-28 12:01:52 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-06-28 12:01:52 +0200 |
commit | 98992c4e4b3231a99eb5ff17c44e96fe79a6cff2 (patch) | |
tree | e8c8a1ae310303bb6af32cdf53b68bf691b1d867 /lib | |
parent | b21ee2ee36e1aaddbe0b3541a8cac5f117143b66 (diff) | |
download | gitlab-ce-98992c4e4b3231a99eb5ff17c44e96fe79a6cff2.tar.gz |
Add initial build stage_id ref background migration
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/migrate_build_stage_id_reference.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb b/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb index b554c3e079b..87c6c4ed49f 100644 --- a/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb +++ b/lib/gitlab/background_migration/migrate_build_stage_id_reference.rb @@ -1,15 +1,19 @@ module Gitlab module BackgroundMigration class MigrateBuildStageIdReference - class Build < ActiveRecord::Base - self.table_name = 'ci_builds' - end + def perform(id) + raise ArgumentError unless id.is_a?(Integer) - class Stage < ActiveRecord::Base - self.table_name = 'ci_stages' - end + sql = <<-SQL.strip_heredoc + UPDATE "ci_builds" SET "stage_id" = ( + SELECT id FROM ci_stages + WHERE ci_stages.pipeline_id = ci_builds.commit_id + AND ci_stages.name = ci_builds.stage + ) + WHERE "ci_builds"."id" = #{id} AND "ci_builds"."stage_id" IS NULL + SQL - def perform(id) + ActiveRecord::Base.connection.execute(sql) end end end |