Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-28 13:01:52 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-28 13:01:52 +0300
commit98992c4e4b3231a99eb5ff17c44e96fe79a6cff2 (patch)
treee8c8a1ae310303bb6af32cdf53b68bf691b1d867 /lib/gitlab/background_migration
parentb21ee2ee36e1aaddbe0b3541a8cac5f117143b66 (diff)
Add initial build stage_id ref background migration
Diffstat (limited to 'lib/gitlab/background_migration')
-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