summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 03:08:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 03:08:01 +0000
commit796b00a98a82fcbe082c9343fd4efcccc77478dc (patch)
tree257bcb124f57cb91a8dff75e69649e8a2f91c51d /db
parent93dcf45d441bc884b167f4338380c8c888e9b86f (diff)
downloadgitlab-ce-796b00a98a82fcbe082c9343fd4efcccc77478dc.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200313202430_add_index_chat_name_service_id.rb17
-rw-r--r--db/migrate/20200313203525_add_invalid_foreign_key_from_chat_name_to_service.rb16
-rw-r--r--db/post_migrate/20200313203550_remove_orphaned_chat_names.rb13
-rw-r--r--db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb14
-rw-r--r--db/structure.sql9
5 files changed, 69 insertions, 0 deletions
diff --git a/db/migrate/20200313202430_add_index_chat_name_service_id.rb b/db/migrate/20200313202430_add_index_chat_name_service_id.rb
new file mode 100644
index 00000000000..f4a88973751
--- /dev/null
+++ b/db/migrate/20200313202430_add_index_chat_name_service_id.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexChatNameServiceId < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :chat_names, :service_id
+ end
+
+ def down
+ remove_concurrent_index :chat_names, :service_id
+ end
+end
diff --git a/db/migrate/20200313203525_add_invalid_foreign_key_from_chat_name_to_service.rb b/db/migrate/20200313203525_add_invalid_foreign_key_from_chat_name_to_service.rb
new file mode 100644
index 00000000000..c6e340693f8
--- /dev/null
+++ b/db/migrate/20200313203525_add_invalid_foreign_key_from_chat_name_to_service.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddInvalidForeignKeyFromChatNameToService < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :chat_names, :services, column: :service_id, on_delete: :cascade, validate: false
+ end
+
+ def down
+ remove_foreign_key_if_exists :chat_names, column: :service_id
+ end
+end
diff --git a/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb b/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb
new file mode 100644
index 00000000000..59cd2b31772
--- /dev/null
+++ b/db/post_migrate/20200313203550_remove_orphaned_chat_names.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RemoveOrphanedChatNames < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ execute("DELETE FROM chat_names WHERE service_id NOT IN(SELECT id FROM services WHERE services.type = 'chat')")
+ end
+
+ def down
+ say 'Orphaned user chat names were removed as a part of this migration and are non-recoverable'
+ end
+end
diff --git a/db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb b/db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb
new file mode 100644
index 00000000000..fd9feab17db
--- /dev/null
+++ b/db/post_migrate/20200313204021_validate_foreign_key_from_chat_name_to_service.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class ValidateForeignKeyFromChatNameToService < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+ DOWNTIME = false
+
+ def up
+ validate_foreign_key :chat_names, :service_id
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index d5bd08b41d0..86a931b6cb4 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -8627,6 +8627,8 @@ CREATE INDEX index_boards_on_project_id ON public.boards USING btree (project_id
CREATE INDEX index_broadcast_message_on_ends_at_and_broadcast_type_and_id ON public.broadcast_messages USING btree (ends_at, broadcast_type, id);
+CREATE INDEX index_chat_names_on_service_id ON public.chat_names USING btree (service_id);
+
CREATE UNIQUE INDEX index_chat_names_on_service_id_and_team_id_and_chat_id ON public.chat_names USING btree (service_id, team_id, chat_id);
CREATE UNIQUE INDEX index_chat_names_on_user_id_and_service_id ON public.chat_names USING btree (user_id, service_id);
@@ -10333,6 +10335,9 @@ CREATE UNIQUE INDEX vulnerability_feedback_unique_idx ON public.vulnerability_fe
CREATE UNIQUE INDEX vulnerability_occurrence_pipelines_on_unique_keys ON public.vulnerability_occurrence_pipelines USING btree (occurrence_id, pipeline_id);
+ALTER TABLE ONLY public.chat_names
+ ADD CONSTRAINT fk_00797a2bf9 FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;
+
ALTER TABLE ONLY public.epics
ADD CONSTRAINT fk_013c9f36ca FOREIGN KEY (due_date_sourcing_epic_id) REFERENCES public.epics(id) ON DELETE SET NULL;
@@ -12879,6 +12884,10 @@ COPY "schema_migrations" (version) FROM STDIN;
20200312163407
20200313101649
20200313123934
+20200313202430
+20200313203525
+20200313203550
+20200313204021
20200314060834
20200316111759
20200316162648