From 4a7d2b21b118ca038ef76b7a7ed85de5569a8267 Mon Sep 17 00:00:00 2001 From: Paul Slaughter Date: Thu, 16 Nov 2023 21:24:24 -0600 Subject: [PATCH] Db migrations for IDE OAuth - See [original Spike MR][1] for implementation direction [1]: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132496 Changelog: other --- ...d_web_ide_oauth_application_to_settings.rb | 9 ++++++++ ...031559_add_fk_web_ide_oauth_application.rb | 22 +++++++++++++++++++ db/schema_migrations/20231117031416 | 1 + db/schema_migrations/20231117031559 | 1 + db/structure.sql | 6 +++++ 5 files changed, 39 insertions(+) create mode 100644 db/migrate/20231117031416_add_web_ide_oauth_application_to_settings.rb create mode 100644 db/migrate/20231117031559_add_fk_web_ide_oauth_application.rb create mode 100644 db/schema_migrations/20231117031416 create mode 100644 db/schema_migrations/20231117031559 diff --git a/db/migrate/20231117031416_add_web_ide_oauth_application_to_settings.rb b/db/migrate/20231117031416_add_web_ide_oauth_application_to_settings.rb new file mode 100644 index 00000000000000..6d368f19e92d9f --- /dev/null +++ b/db/migrate/20231117031416_add_web_ide_oauth_application_to_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddWebIdeOauthApplicationToSettings < Gitlab::Database::Migration[2.2] + milestone '16.7' + + def change + add_column :application_settings, :web_ide_oauth_application_id, :int, null: true + end +end diff --git a/db/migrate/20231117031559_add_fk_web_ide_oauth_application.rb b/db/migrate/20231117031559_add_fk_web_ide_oauth_application.rb new file mode 100644 index 00000000000000..61da3edbb30e6b --- /dev/null +++ b/db/migrate/20231117031559_add_fk_web_ide_oauth_application.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddFkWebIdeOauthApplication < Gitlab::Database::Migration[2.2] + milestone '16.7' + disable_ddl_transaction! + + INDEX_NAME = 'index_application_settings_web_ide_oauth_application_id' + + def up + add_concurrent_index :application_settings, :web_ide_oauth_application_id, name: INDEX_NAME + add_concurrent_foreign_key :application_settings, :oauth_applications, + column: :web_ide_oauth_application_id, + on_delete: :nullify + end + + def down + with_lock_retries do + remove_foreign_key :application_settings, column: :web_ide_oauth_application_id + end + remove_concurrent_index_by_name :application_settings, INDEX_NAME + end +end diff --git a/db/schema_migrations/20231117031416 b/db/schema_migrations/20231117031416 new file mode 100644 index 00000000000000..b466bfad8f995c --- /dev/null +++ b/db/schema_migrations/20231117031416 @@ -0,0 +1 @@ +f9d770cc47aa6a7ec1ff0e2f70ee7fbc6f1071e159fd8f722959730222dbf6eb \ No newline at end of file diff --git a/db/schema_migrations/20231117031559 b/db/schema_migrations/20231117031559 new file mode 100644 index 00000000000000..e2ccf7144d4c3f --- /dev/null +++ b/db/schema_migrations/20231117031559 @@ -0,0 +1 @@ +57c6bd774242b5fd6383bd393dfc90007f5f7fef21f2c83d3252f19cd1518e78 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index d7ba2e8a75569f..885ad0106c7bc7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -12202,6 +12202,7 @@ CREATE TABLE application_settings ( update_namespace_name_rate_limit smallint DEFAULT 120 NOT NULL, pre_receive_secret_detection_enabled boolean DEFAULT false NOT NULL, can_create_organization boolean DEFAULT true NOT NULL, + web_ide_oauth_application_id integer, CONSTRAINT app_settings_container_reg_cleanup_tags_max_list_size_positive CHECK ((container_registry_cleanup_tags_service_max_list_size >= 0)), CONSTRAINT app_settings_container_registry_pre_import_tags_rate_positive CHECK ((container_registry_pre_import_tags_rate >= (0)::numeric)), CONSTRAINT app_settings_dep_proxy_ttl_policies_worker_capacity_positive CHECK ((dependency_proxy_ttl_group_policy_worker_capacity >= 0)), @@ -31658,6 +31659,8 @@ CREATE UNIQUE INDEX index_application_settings_on_push_rule_id ON application_se CREATE INDEX index_application_settings_on_usage_stats_set_by_user_id ON application_settings USING btree (usage_stats_set_by_user_id); +CREATE INDEX index_application_settings_web_ide_oauth_application_id ON application_settings USING btree (web_ide_oauth_application_id); + CREATE INDEX index_applicationsettings_on_instance_administration_project_id ON application_settings USING btree (instance_administration_project_id); CREATE INDEX index_approval_group_rules_groups_on_group_id ON approval_group_rules_groups USING btree (group_id); @@ -38154,6 +38157,9 @@ ALTER TABLE ONLY cluster_agents ALTER TABLE ONLY protected_tag_create_access_levels ADD CONSTRAINT fk_f7dfda8c51 FOREIGN KEY (protected_tag_id) REFERENCES protected_tags(id) ON DELETE CASCADE; +ALTER TABLE ONLY application_settings + ADD CONSTRAINT fk_f9867b3540 FOREIGN KEY (web_ide_oauth_application_id) REFERENCES oauth_applications(id) ON DELETE SET NULL; + ALTER TABLE ONLY ci_stages ADD CONSTRAINT fk_fb57e6cc56 FOREIGN KEY (pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE; -- GitLab