debian-mirror-gitlab/db/post_migrate/20170526185842_migrate_pipeline_stages.rb

23 lines
716 B
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
class MigratePipelineStages < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
2018-11-20 20:47:30 +05:30
disable_statement_timeout do
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
AND stage_id IS NULL
AND EXISTS (SELECT 1 FROM projects WHERE projects.id = ci_builds.project_id)
AND EXISTS (SELECT 1 FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id)
GROUP BY project_id, commit_id, stage
ORDER BY MAX(stage_idx)
SQL
end
2017-09-10 17:25:29 +05:30
end
end