Commit 3326291f authored by Grzegorz Bizon's avatar Grzegorz Bizon

Remove obsolete stages/build before adding foreign keys

parent 06898af3
......@@ -6,6 +6,22 @@ class CreateForeignKeysForPipelineStages < ActiveRecord::Migration
disable_ddl_transaction!
def up
execute <<~SQL
DELETE FROM ci_stages
WHERE NOT EXISTS (
SELECT true FROM projects
WHERE projects.id = ci_stages.project_id
)
SQL
execute <<~SQL
DELETE FROM ci_builds
WHERE NOT EXISTS (
SELECT true FROM ci_stages
WHERE ci_stages.id = ci_builds.stage_id
)
SQL
add_concurrent_foreign_key :ci_stages, :projects, column: :project_id, on_delete: :cascade
add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment