2018-11-13 07:27:31 +00:00
|
|
|
class MigratePipelineStages < ActiveRecord::Migration[4.2]
|
2017-05-26 12:46:45 +00:00
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
2018-08-10 23:45:46 +00:00
|
|
|
disable_statement_timeout do
|
2018-07-09 21:31:45 +00:00
|
|
|
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-05-26 12:46:45 +00:00
|
|
|
end
|
|
|
|
end
|