summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-28 12:01:52 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-07 15:07:29 +0200
commitb7d672328db358690d043aae8b5fc24c358a52ab (patch)
treec3c79c0c0e39a93e8475d88cd8190a98e65cfe17 /lib
parent16ae7b7a49314b2525f3f32c07dd8a4891fa74e1 (diff)
downloadgitlab-ce-b7d672328db358690d043aae8b5fc24c358a52ab.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.rb18
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