diff options
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.rb | 16 |
1 files changed, 16 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 index 4c2c242c01a..8298979e96a 100644 --- a/db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb +++ b/db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb @@ -9,12 +9,28 @@ class EnsureForeignKeysOnClustersApplications < ActiveRecord::Migration disable_ddl_transaction! def up + existing = Clusters::Cluster + .joins(:application_ingress) + .where('clusters.id = clusters_applications_ingress.cluster_id') + + Clusters::Applications::Ingress.where('NOT EXISTS (?)', existing).in_batches do |batch| + batch.delete_all + end + 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 + existing = Clusters::Cluster + .joins(:application_prometheus) + .where('clusters.id = clusters_applications_prometheus.cluster_id') + + Clusters::Applications::Ingress.where('NOT EXISTS (?)', existing).in_batches do |batch| + batch.delete_all + end + unless foreign_keys_for(:clusters_applications_prometheus, :cluster_id).any? add_concurrent_foreign_key :clusters_applications_prometheus, :clusters, column: :cluster_id, |