diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-05-08 21:52:27 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-05-11 14:52:47 +0200 |
commit | 3eb8435fec3cd7311544a256a3205f31d1dc3a0c (patch) | |
tree | b365ae6f43343f352a7214ad85a31c82c862dc9d /db/migrate/20170508190732_add_foreign_key_to_ci_variables.rb | |
parent | 383883382bac97477eb8448bef3ffac15d7ceacf (diff) | |
download | gitlab-ce-3eb8435fec3cd7311544a256a3205f31d1dc3a0c.tar.gz |
Add a foreign key to ci_variables to projects
Variables shouldn't exist without a project, so a foreign key was added
with CASCADE'ing effects.
Diffstat (limited to 'db/migrate/20170508190732_add_foreign_key_to_ci_variables.rb')
-rw-r--r-- | db/migrate/20170508190732_add_foreign_key_to_ci_variables.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/db/migrate/20170508190732_add_foreign_key_to_ci_variables.rb b/db/migrate/20170508190732_add_foreign_key_to_ci_variables.rb new file mode 100644 index 00000000000..13837324787 --- /dev/null +++ b/db/migrate/20170508190732_add_foreign_key_to_ci_variables.rb @@ -0,0 +1,25 @@ +class AddForeignKeyToCiVariables < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + execute <<~SQL + DELETE FROM ci_variables + WHERE NOT EXISTS ( + SELECT true + FROM projects + WHERE projects.id = ci_variables.project_id + ) + OR ci_variables.project_id IS NULL + SQL + + add_concurrent_foreign_key(:ci_variables, :projects, column: :project_id) + end + + def down + remove_foreign_key(:ci_variables, column: :project_id) + end +end |