summaryrefslogtreecommitdiff
path: root/db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-03-02 09:42:08 -0600
committerMayra Cabrera <mcabrera@gitlab.com>2018-03-07 15:45:19 -0600
commite9657acfc3433ea98a48d90312160e2e9cc8b173 (patch)
treeb43c035cfcd793ea976ec24afd86adb26735606f /db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb
parent98c8c90e92f8f0407bf048d42ff5e4d76ce57ba0 (diff)
downloadgitlab-ce-e9657acfc3433ea98a48d90312160e2e9cc8b173.tar.gz
Ensure foreign keys on Clusters Applications
Closes #43802
Diffstat (limited to 'db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb')
-rw-r--r--db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb b/db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb
new file mode 100644
index 00000000000..4c2c242c01a
--- /dev/null
+++ b/db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb
@@ -0,0 +1,34 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class EnsureForeignKeysOnClustersApplications < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ unless foreign_keys_for(:clusters_applications_ingress, :cluster_id).any?
+ add_concurrent_foreign_key :clusters_applications_ingress, :clusters,
+ column: :cluster_id,
+ on_delete: :cascade
+ end
+
+ unless foreign_keys_for(:clusters_applications_prometheus, :cluster_id).any?
+ add_concurrent_foreign_key :clusters_applications_prometheus, :clusters,
+ column: :cluster_id,
+ on_delete: :cascade
+ end
+ end
+
+ def down
+ if foreign_keys_for(:clusters_applications_ingress, :cluster_id).any?
+ remove_foreign_key :clusters_applications_ingress, column: :cluster_id
+ end
+
+ if foreign_keys_for(:clusters_applications_prometheus, :cluster_id).any?
+ remove_foreign_key :clusters_applications_prometheus, column: :cluster_id
+ end
+ end
+end