diff --git a/db/migrate/20240528055716_add_unique_index_to_project_framework_settings_on_project_framework_id.rb b/db/migrate/20240528055716_add_unique_index_to_project_framework_settings_on_project_framework_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..08c2ae788dd64115e2c0e7df1eb8f209822832fe --- /dev/null +++ b/db/migrate/20240528055716_add_unique_index_to_project_framework_settings_on_project_framework_id.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddUniqueIndexToProjectFrameworkSettingsOnProjectFrameworkId < Gitlab::Database::Migration[2.2] + milestone '17.1' + disable_ddl_transaction! + + EXISTING_INDEX_NAME = 'index_project_compliance_framework_settings_on_project_id' + NEW_INDEX_NAME = 'uniq_idx_project_compliance_framework_on_project_framework' + COLUMNS = %i[project_id framework_id] + + def up + remove_concurrent_index_by_name :project_compliance_framework_settings, EXISTING_INDEX_NAME + + add_concurrent_index :project_compliance_framework_settings, COLUMNS, unique: true, name: NEW_INDEX_NAME + end + + def down + remove_concurrent_index_by_name :project_compliance_framework_settings, NEW_INDEX_NAME + + add_concurrent_index :project_compliance_framework_settings, :project_id, name: EXISTING_INDEX_NAME + end +end diff --git a/db/migrate/20240528060203_change_primary_key_of_project_compliance_framework_settings.rb b/db/migrate/20240528060203_change_primary_key_of_project_compliance_framework_settings.rb new file mode 100644 index 0000000000000000000000000000000000000000..1b7520538935ff921f34205244aeb6a6d2c80786 --- /dev/null +++ b/db/migrate/20240528060203_change_primary_key_of_project_compliance_framework_settings.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ChangePrimaryKeyOfProjectComplianceFrameworkSettings < Gitlab::Database::Migration[2.2] + milestone '17.1' + disable_ddl_transaction! + + def up + execute <<~SQL + ALTER TABLE project_compliance_framework_settings DROP CONSTRAINT IF EXISTS project_compliance_framework_settings_pkey + SQL + + add_column :project_compliance_framework_settings, :id, :primary_key, if_not_exists: true + end + + def down + with_lock_retries do + remove_column :project_compliance_framework_settings, :id, if_exists: true + end + + execute <<~SQL + ALTER TABLE project_compliance_framework_settings ADD PRIMARY KEY (project_id) + SQL + end +end diff --git a/db/schema_migrations/20240528055716 b/db/schema_migrations/20240528055716 new file mode 100644 index 0000000000000000000000000000000000000000..61c86b1cad686a3595b97c3d781868d1a2dcca1e --- /dev/null +++ b/db/schema_migrations/20240528055716 @@ -0,0 +1 @@ +0bf5ab1433ddd13ea0dd7a2a3cbae552f604e2f9e766a1cb0eb08b923f18dced \ No newline at end of file diff --git a/db/schema_migrations/20240528060203 b/db/schema_migrations/20240528060203 new file mode 100644 index 0000000000000000000000000000000000000000..3ec8737bab78c89f223c365f628d70a4c5c4eabd --- /dev/null +++ b/db/schema_migrations/20240528060203 @@ -0,0 +1 @@ +906d79b1523aee16bbc3ab3912f2ffb4c6e9d96bdce00d3176b9b63e829102c3 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 58cd5684dcc0c5bb12e2ef2494ca25912fd0c9b0..edb8c369500c2f9aca925bb748e9a455c6415306 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -14500,9 +14500,19 @@ ALTER SEQUENCE project_ci_feature_usages_id_seq OWNED BY project_ci_feature_usag CREATE TABLE project_compliance_framework_settings ( project_id bigint NOT NULL, framework_id bigint, + id bigint NOT NULL, CONSTRAINT check_d348de9e2d CHECK ((framework_id IS NOT NULL)) ); +CREATE SEQUENCE project_compliance_framework_settings_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE project_compliance_framework_settings_id_seq OWNED BY project_compliance_framework_settings.id; + CREATE SEQUENCE project_compliance_framework_settings_project_id_seq START WITH 1 INCREMENT BY 1 @@ -20051,6 +20061,8 @@ ALTER TABLE ONLY project_ci_feature_usages ALTER COLUMN id SET DEFAULT nextval(' ALTER TABLE ONLY project_compliance_framework_settings ALTER COLUMN project_id SET DEFAULT nextval('project_compliance_framework_settings_project_id_seq'::regclass); +ALTER TABLE ONLY project_compliance_framework_settings ALTER COLUMN id SET DEFAULT nextval('project_compliance_framework_settings_id_seq'::regclass); + ALTER TABLE ONLY project_compliance_standards_adherence ALTER COLUMN id SET DEFAULT nextval('project_compliance_standards_adherence_id_seq'::regclass); ALTER TABLE ONLY project_custom_attributes ALTER COLUMN id SET DEFAULT nextval('project_custom_attributes_id_seq'::regclass); @@ -22510,7 +22522,7 @@ ALTER TABLE ONLY project_ci_feature_usages ADD CONSTRAINT project_ci_feature_usages_pkey PRIMARY KEY (id); ALTER TABLE ONLY project_compliance_framework_settings - ADD CONSTRAINT project_compliance_framework_settings_pkey PRIMARY KEY (project_id); + ADD CONSTRAINT project_compliance_framework_settings_pkey PRIMARY KEY (id); ALTER TABLE ONLY project_compliance_standards_adherence ADD CONSTRAINT project_compliance_standards_adherence_pkey PRIMARY KEY (id); @@ -27183,8 +27195,6 @@ CREATE UNIQUE INDEX index_project_ci_feature_usages_unique_columns ON project_ci CREATE INDEX index_project_compliance_framework_settings_on_framework_id ON project_compliance_framework_settings USING btree (framework_id); -CREATE INDEX index_project_compliance_framework_settings_on_project_id ON project_compliance_framework_settings USING btree (project_id); - CREATE INDEX index_project_compliance_standards_adherence_on_project_id ON project_compliance_standards_adherence USING btree (project_id); CREATE INDEX index_project_custom_attributes_on_key_and_value ON project_custom_attributes USING btree (key, value); @@ -28539,6 +28549,8 @@ CREATE UNIQUE INDEX uniq_google_cloud_logging_configuration_namespace_id_and_nam CREATE UNIQUE INDEX uniq_idx_packages_packages_on_project_id_name_version_ml_model ON packages_packages USING btree (project_id, name, version) WHERE ((package_type = 14) AND (status <> 4)); +CREATE UNIQUE INDEX uniq_idx_project_compliance_framework_on_project_framework ON project_compliance_framework_settings USING btree (project_id, framework_id); + CREATE UNIQUE INDEX uniq_idx_streaming_destination_id_and_namespace_id ON audit_events_streaming_instance_namespace_filters USING btree (external_streaming_destination_id, namespace_id); CREATE UNIQUE INDEX uniq_idx_streaming_group_destination_id_and_namespace_id ON audit_events_streaming_group_namespace_filters USING btree (external_streaming_destination_id, namespace_id);