diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-05-08 20:01:53 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-05-08 20:01:53 +0300 |
commit | b215db37f878bfc4a753705e453f74b8db6546e4 (patch) | |
tree | 4faa425911d44a4c85b7a4b0201702ab714d6fea /db | |
parent | 533593e95cd3a922a2ec2ea43b345862361dfd67 (diff) | |
parent | fc8221ce6cae99326a0a519daa0ca7abe27e2728 (diff) |
Merge branch 'fix/gb/add-pipeline-builds-foreign-key' into 'master'
Add database foreign key between pipelines and builds
Closes #46035
See merge request gitlab-org/gitlab-ce!18822
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20180420010016_add_pipeline_build_foreign_key.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb b/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb new file mode 100644 index 00000000000..6fabe07bc9c --- /dev/null +++ b/db/migrate/20180420010016_add_pipeline_build_foreign_key.rb @@ -0,0 +1,27 @@ +class AddPipelineBuildForeignKey < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + execute <<~SQL + DELETE FROM ci_builds WHERE project_id IS NULL OR commit_id IS NULL + SQL + + execute <<~SQL + DELETE FROM ci_builds WHERE NOT EXISTS + (SELECT true FROM ci_pipelines WHERE ci_pipelines.id = ci_builds.commit_id) + AND stage_id IS NULL + SQL + + add_concurrent_foreign_key(:ci_builds, :ci_pipelines, column: :commit_id) + end + + def down + return unless foreign_key_exists?(:ci_builds, :ci_pipelines, column: :commit_id) + + remove_foreign_key(:ci_builds, column: :commit_id) + end +end |