summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-06-24 09:48:16 +1200
committerThong Kuah <tkuah@gitlab.com>2019-06-27 17:28:48 +1200
commit525edec78bc39ae41284927f1866def56d21a12a (patch)
treee59fd0498b9dd9396838594a6834b0642142ae50 /db/migrate
parent871d06993edba9220c10ef2ca5c64f412ee5f984 (diff)
downloadgitlab-ce-525edec78bc39ae41284927f1866def56d21a12a.tar.gz
Add cluster_id to deployments table as an FK
We nullify when cluster is deleted as we want to keep the deployment record around. Add cluster as an optional association We will have only cluster for deployments where the build deploys to a kubernetes cluster
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20190623212503_add_cluster_id_to_deployments.rb9
-rw-r--r--db/migrate/20190627051902_add_cluster_id_index_fk_to_deployments.rb21
2 files changed, 30 insertions, 0 deletions
diff --git a/db/migrate/20190623212503_add_cluster_id_to_deployments.rb b/db/migrate/20190623212503_add_cluster_id_to_deployments.rb
new file mode 100644
index 00000000000..cd0c4191568
--- /dev/null
+++ b/db/migrate/20190623212503_add_cluster_id_to_deployments.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddClusterIdToDeployments < ActiveRecord::Migration[5.1]
+ DOWNTIME = false
+
+ def change
+ add_column :deployments, :cluster_id, :integer
+ end
+end
diff --git a/db/migrate/20190627051902_add_cluster_id_index_fk_to_deployments.rb b/db/migrate/20190627051902_add_cluster_id_index_fk_to_deployments.rb
new file mode 100644
index 00000000000..f41e5c80269
--- /dev/null
+++ b/db/migrate/20190627051902_add_cluster_id_index_fk_to_deployments.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddClusterIdIndexFkToDeployments < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :deployments, :cluster_id
+
+ add_concurrent_foreign_key :deployments, :clusters, column: :cluster_id, on_delete: :nullify
+ end
+
+ def down
+ remove_foreign_key :deployments, :clusters
+
+ remove_concurrent_index :deployments, :cluster_id
+ end
+end