diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-05-16 09:18:55 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-05-16 09:18:55 +0000 |
commit | b0ce5e1e307f5696aa3d9b030a3bce424becb3b5 (patch) | |
tree | 32b961370888361510bcfecd617d337d892f9beb /db | |
parent | 791dd5a6f134088f5cbf3ecf7bab23cf2f63b3a1 (diff) | |
parent | 02e156c2e726c2b06df87d371511694f0e03027e (diff) | |
download | gitlab-ce-b0ce5e1e307f5696aa3d9b030a3bce424becb3b5.tar.gz |
Merge branch 'zj-pipeline-schedule-owner' into 'master'
Foreign key for Pipeline schedule owner
Closes #31932
See merge request !11233
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb | 35 | ||||
-rw-r--r-- | db/schema.rb | 3 |
2 files changed, 37 insertions, 1 deletions
diff --git a/db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb b/db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb new file mode 100644 index 00000000000..6a870f08e89 --- /dev/null +++ b/db/post_migrate/20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb @@ -0,0 +1,35 @@ +class AddForeignKeyOnPipelineScheduleOwner < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + execute <<-SQL + UPDATE ci_pipeline_schedules + SET owner_id = NULL + WHERE NOT EXISTS ( + SELECT true + FROM users + WHERE ci_pipeline_schedules.owner_id = users.id + ) + SQL + + add_concurrent_foreign_key(:ci_pipeline_schedules, :users, column: :owner_id, on_delete: on_delete) + end + + def down + remove_foreign_key(:ci_pipeline_schedules, column: :owner_id) + end + + private + + def on_delete + if Gitlab::Database.mysql? + :nullify + else + 'SET NULL' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a683521c84b..fd0fb2d7220 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170508190732) do +ActiveRecord::Schema.define(version: 20170510101043) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1416,6 +1416,7 @@ ActiveRecord::Schema.define(version: 20170508190732) do add_foreign_key "chat_teams", "namespaces", on_delete: :cascade add_foreign_key "ci_builds", "ci_pipelines", column: "auto_canceled_by_id", name: "fk_a2141b1522", on_delete: :nullify add_foreign_key "ci_pipeline_schedules", "projects", name: "fk_8ead60fcc4", on_delete: :cascade + add_foreign_key "ci_pipeline_schedules", "users", column: "owner_id", name: "fk_9ea99f58d2", on_delete: :nullify add_foreign_key "ci_pipelines", "ci_pipeline_schedules", column: "pipeline_schedule_id", name: "fk_3d34ab2e06", on_delete: :nullify add_foreign_key "ci_pipelines", "ci_pipelines", column: "auto_canceled_by_id", name: "fk_262d4c2d19", on_delete: :nullify add_foreign_key "ci_trigger_requests", "ci_triggers", column: "trigger_id", name: "fk_b8ec8b7245", on_delete: :cascade |