Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 11:17:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 11:17:02 +0300
commitb39512ed755239198a9c294b6a45e65c05900235 (patch)
treed234a3efade1de67c46b9e5a38ce813627726aa7 /db/migrate
parentd31474cf3b17ece37939d20082b07f6657cc79a9 (diff)
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb2
-rw-r--r--db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb70
-rw-r--r--db/migrate/20210804150320_create_base_work_item_types.rb6
-rw-r--r--db/migrate/20210831203408_upsert_base_work_item_types.rb6
-rw-r--r--db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb5
-rw-r--r--db/migrate/20220316022505_create_namespace_details.rb21
-rw-r--r--db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb4
-rw-r--r--db/migrate/20220506154054_create_sync_namespace_details_trigger.rb70
-rw-r--r--db/migrate/20220513093614_add_ding_talk_into_application_settings.rb4
-rw-r--r--db/migrate/20220513093615_add_ding_talk_tracker_data.rb2
-rw-r--r--db/migrate/20220524184149_create_sync_project_namespace_details_trigger.rb68
-rw-r--r--db/migrate/20220619212618_add_selective_code_owner_removals_to_project_settings.rb9
-rw-r--r--db/migrate/20220627061008_add_fei_shu_integration.rb4
-rw-r--r--db/migrate/20220707105335_rename_chat_name_service_id_to_integration_id.rb13
-rw-r--r--db/migrate/20220707160707_rename_slack_integration_service_id_to_integration_id.rb13
-rw-r--r--db/migrate/20220707181910_create_member_roles.rb15
-rw-r--r--db/migrate/20220707181920_add_member_role_id_to_members.rb13
-rw-r--r--db/migrate/20220707181930_add_member_roles_relation_to_members.rb19
-rw-r--r--db/migrate/20220707190546_add_plan_limits_max_size_cyclonedx_report_column.rb7
-rw-r--r--db/migrate/20220708150315_add_vulnerabilities_foreign_key_to_vulnerability_merge_request_links.rb4
-rw-r--r--db/migrate/20220708150335_add_merge_requests_foreign_key_to_vulnerability_merge_request_links.rb4
-rw-r--r--db/migrate/20220712131513_rename_issue_tracker_data_service_id_to_integration_id.rb13
-rw-r--r--db/migrate/20220712144843_rename_jira_tracker_data_service_id_to_integration_id.rb13
-rw-r--r--db/migrate/20220718083945_add_unique_project_download_limit_allowlist_to_namespace_settings.rb11
-rw-r--r--db/migrate/20220720161816_add_namespace_id_to_vulnerability_reads_table.rb9
-rw-r--r--db/migrate/20220720162123_update_vulnerability_reads_triggers_to_set_namespace_id.rb159
-rw-r--r--db/migrate/20220720210446_add_start_date_to_issues_table.rb9
-rw-r--r--db/migrate/20220722123318_update_delayed_deletion_period.rb27
-rw-r--r--db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb32
-rw-r--r--db/migrate/20220722203840_update_lock_writes_function_disabled_via_setting.rb36
-rw-r--r--db/migrate/20220723120039_add_author_id_to_vulnerability_state_transitions.rb7
-rw-r--r--db/migrate/20220726025516_add_namespace_settings_unique_project_download_limit_allowlist_size_constraint.rb17
-rw-r--r--db/migrate/20220726154012_ensure_sbom_occurrences_is_empty.rb18
-rw-r--r--db/migrate/20220726154013_add_component_id_to_sbom_occurrences.rb17
-rw-r--r--db/migrate/20220726154014_add_index_to_sbom_occurrences_component_id.rb15
-rw-r--r--db/migrate/20220726154015_add_component_foreign_key_to_sbom_occurrences.rb18
-rw-r--r--db/migrate/20220726154016_make_component_version_nullable.rb9
-rw-r--r--db/migrate/20220726230052_remove_tmp_index_project_membership_namespace_id_column.rb20
-rw-r--r--db/migrate/20220728114136_make_ssh_signature_key_nullable.rb9
-rw-r--r--db/migrate/20220729073603_index_personal_access_tokens_on_id_and_created_at.rb15
-rw-r--r--db/migrate/20220802154757_add_deactivate_dormant_user_time_setting.rb6
-rw-r--r--db/migrate/20220803145637_create_user_project_callout.rb19
-rw-r--r--db/migrate/20220803154543_add_project_id_fkey_for_user_project_callout.rb15
-rw-r--r--db/migrate/20220803154758_add_user_id_fkey_for_user_project_callout.rb15
-rw-r--r--db/migrate/20220805154101_add_allow_run_pipelines_in_the_parent_project_setting.rb8
-rw-r--r--db/migrate/20220808133824_add_timestamps_to_project_statistics.rb7
-rw-r--r--db/migrate/20220808190124_add_id_token_to_ci_builds_metadata.rb9
-rw-r--r--db/migrate/20220808194857_remove_description_html_limit.rb15
-rw-r--r--db/migrate/20220811092243_create_ml_experiments.rb18
-rw-r--r--db/migrate/20220811092244_create_ml_candidates.rb16
-rw-r--r--db/migrate/20220811092245_create_ml_candidate_params.rb14
-rw-r--r--db/migrate/20220811092246_create_ml_candidate_metrics.rb16
-rw-r--r--db/migrate/20220811092251_add_ml_candidates_reference_to_experiment.rb15
-rw-r--r--db/migrate/20220811092253_add_ml_experiments_reference_to_project.rb15
54 files changed, 913 insertions, 88 deletions
diff --git a/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb b/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb
index 611619e496c..1109d814ee9 100644
--- a/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb
+++ b/db/migrate/20210601080039_group_protected_environments_add_index_and_constraint.rb
@@ -9,7 +9,7 @@ class GroupProtectedEnvironmentsAddIndexAndConstraint < ActiveRecord::Migration[
def up
add_concurrent_index :protected_environments, [:group_id, :name], unique: true,
- name: INDEX_NAME, where: 'group_id IS NOT NULL'
+ name: INDEX_NAME, where: 'group_id IS NOT NULL'
add_concurrent_foreign_key :protected_environments, :namespaces, column: :group_id, on_delete: :cascade
add_check_constraint :protected_environments,
diff --git a/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb b/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb
index 5db39334550..14b6b9efad3 100644
--- a/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb
+++ b/db/migrate/20210629031900_associate_existing_dast_builds_with_variables.rb
@@ -1,77 +1,11 @@
# frozen_string_literal: true
class AssociateExistingDastBuildsWithVariables < ActiveRecord::Migration[6.1]
- disable_ddl_transaction!
-
- class Profile < ApplicationRecord
- self.table_name = 'dast_profiles'
- self.inheritance_column = :_type_disabled
- end
-
- class ProfilesPipeline < ApplicationRecord
- include EachBatch
-
- self.table_name = 'dast_profiles_pipelines'
- self.inheritance_column = :_type_disabled
-
- belongs_to :profile, foreign_key: :dast_profile_id
- end
-
- class Build < ApplicationRecord
- self.table_name = 'ci_builds'
- self.inheritance_column = :_type_disabled
-
- default_scope { where(name: :dast, stage: :dast) } # rubocop:disable Cop/DefaultScope
- end
-
- class SiteProfilesBuild < ApplicationRecord
- self.table_name = 'dast_site_profiles_builds'
- self.inheritance_column = :_type_disabled
- end
-
- BATCH_SIZE = 300
-
def up
- process_batch do |batch|
- bulk_inserts = []
-
- grouped_builds = fetch_builds(batch).group_by(&:commit_id)
-
- batch.includes(:profile).each do |profile_pipeline|
- builds = grouped_builds[profile_pipeline.ci_pipeline_id]
-
- next if builds.blank?
-
- builds.each do |build|
- bulk_inserts.push(dast_site_profile_id: profile_pipeline.profile.dast_site_profile_id, ci_build_id: build.id)
- end
- end
-
- SiteProfilesBuild.insert_all(bulk_inserts, unique_by: :ci_build_id)
- end
+ # no-op: Must have run before %"15.X" as it is not compatible with decomposed CI database
end
def down
- process_batch do |batch|
- builds = fetch_builds(batch)
-
- SiteProfilesBuild
- .where(ci_build_id: builds)
- .delete_all
- end
- end
-
- private
-
- def fetch_builds(batch)
- # pluck necessary to support ci table decomposition
- # https://gitlab.com/groups/gitlab-org/-/epics/6289
- Build.where(commit_id: batch.pluck(:ci_pipeline_id))
- end
-
- def process_batch
- ProfilesPipeline.each_batch(of: BATCH_SIZE, column: :ci_pipeline_id) do |batch|
- yield(batch)
- end
+ # No-op
end
end
diff --git a/db/migrate/20210804150320_create_base_work_item_types.rb b/db/migrate/20210804150320_create_base_work_item_types.rb
index b7a44eaabe0..836264aae6e 100644
--- a/db/migrate/20210804150320_create_base_work_item_types.rb
+++ b/db/migrate/20210804150320_create_base_work_item_types.rb
@@ -8,9 +8,9 @@ class CreateBaseWorkItemTypes < ActiveRecord::Migration[6.1]
self.table_name = 'work_item_types'
enum base_type: {
- issue: 0,
- incident: 1,
- test_case: 2,
+ issue: 0,
+ incident: 1,
+ test_case: 2,
requirement: 3
}
diff --git a/db/migrate/20210831203408_upsert_base_work_item_types.rb b/db/migrate/20210831203408_upsert_base_work_item_types.rb
index 314412d8d3d..9a556bd6c2c 100644
--- a/db/migrate/20210831203408_upsert_base_work_item_types.rb
+++ b/db/migrate/20210831203408_upsert_base_work_item_types.rb
@@ -6,9 +6,9 @@ class UpsertBaseWorkItemTypes < ActiveRecord::Migration[6.1]
self.table_name = 'work_item_types'
enum base_type: {
- issue: 0,
- incident: 1,
- test_case: 2,
+ issue: 0,
+ incident: 1,
+ test_case: 2,
requirement: 3
}
end
diff --git a/db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb b/db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb
index 77b9e5297a7..e0c9d932b38 100644
--- a/db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb
+++ b/db/migrate/20210901065504_add_index_on_name_and_id_to_public_groups.rb
@@ -7,8 +7,9 @@ class AddIndexOnNameAndIdToPublicGroups < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
- add_concurrent_index :namespaces, [:name, :id], name: INDEX_NAME,
- where: "type = 'Group' AND visibility_level = #{PUBLIC_VISIBILITY_LEVEL}"
+ add_concurrent_index :namespaces, [:name, :id],
+ name: INDEX_NAME,
+ where: "type = 'Group' AND visibility_level = #{PUBLIC_VISIBILITY_LEVEL}"
end
def down
diff --git a/db/migrate/20220316022505_create_namespace_details.rb b/db/migrate/20220316022505_create_namespace_details.rb
new file mode 100644
index 00000000000..6df8606c726
--- /dev/null
+++ b/db/migrate/20220316022505_create_namespace_details.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class CreateNamespaceDetails < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ with_lock_retries do
+ create_table :namespace_details, id: false do |t|
+ t.references :namespace, primary_key: true, null: false, default: nil, type: :bigint, index: false, foreign_key: { on_delete: :cascade } # rubocop:disable Layout/LineLength
+ t.timestamps_with_timezone null: true
+ t.integer :cached_markdown_version
+ t.text :description, limit: 255
+ t.text :description_html, limit: 255
+ end
+ end
+ end
+
+ def down
+ drop_table :namespace_details
+ end
+end
diff --git a/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb b/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb
index 78970d308d9..ffb0fe3f5d8 100644
--- a/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb
+++ b/db/migrate/20220406113217_add_inactive_project_deletion_to_application_settings.rb
@@ -5,7 +5,7 @@ class AddInactiveProjectDeletionToApplicationSettings < Gitlab::Database::Migrat
add_column :application_settings, :delete_inactive_projects, :boolean, default: false, null: false
add_column :application_settings, :inactive_projects_delete_after_months, :integer, default: 2, null: false
add_column :application_settings, :inactive_projects_min_size_mb, :integer, default: 0, null: false
- add_column :application_settings, :inactive_projects_send_warning_email_after_months, :integer, default: 1,
- null: false
+ add_column :application_settings, :inactive_projects_send_warning_email_after_months,
+ :integer, default: 1, null: false
end
end
diff --git a/db/migrate/20220506154054_create_sync_namespace_details_trigger.rb b/db/migrate/20220506154054_create_sync_namespace_details_trigger.rb
new file mode 100644
index 00000000000..1351fe91318
--- /dev/null
+++ b/db/migrate/20220506154054_create_sync_namespace_details_trigger.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+class CreateSyncNamespaceDetailsTrigger < Gitlab::Database::Migration[2.0]
+ include Gitlab::Database::SchemaHelpers
+
+ UPDATE_TRIGGER_NAME = 'trigger_update_details_on_namespace_update'
+ INSERT_TRIGGER_NAME = 'trigger_update_details_on_namespace_insert'
+ FUNCTION_NAME = 'update_namespace_details_from_namespaces'
+
+ enable_lock_retries!
+
+ def up
+ create_trigger_function(FUNCTION_NAME, replace: true) do
+ <<~SQL
+ INSERT INTO
+ namespace_details (
+ description,
+ description_html,
+ cached_markdown_version,
+ updated_at,
+ created_at,
+ namespace_id
+ )
+ VALUES
+ (
+ NEW.description,
+ NEW.description_html,
+ NEW.cached_markdown_version,
+ NEW.updated_at,
+ NEW.updated_at,
+ NEW.id
+ ) ON CONFLICT (namespace_id) DO
+ UPDATE
+ SET
+ description = NEW.description,
+ description_html = NEW.description_html,
+ cached_markdown_version = NEW.cached_markdown_version,
+ updated_at = NEW.updated_at
+ WHERE
+ namespace_details.namespace_id = NEW.id;RETURN NULL;
+ SQL
+ end
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{UPDATE_TRIGGER_NAME}
+ AFTER UPDATE ON namespaces
+ FOR EACH ROW
+ WHEN (
+ NEW.type <> 'Project' AND (
+ OLD.description IS DISTINCT FROM NEW.description OR
+ OLD.description_html IS DISTINCT FROM NEW.description_html OR
+ OLD.cached_markdown_version IS DISTINCT FROM NEW.cached_markdown_version)
+ )
+ EXECUTE PROCEDURE #{FUNCTION_NAME}();
+ SQL
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{INSERT_TRIGGER_NAME}
+ AFTER INSERT ON namespaces
+ FOR EACH ROW
+ WHEN (NEW.type <> 'Project')
+ EXECUTE PROCEDURE #{FUNCTION_NAME}();
+ SQL
+ end
+
+ def down
+ drop_trigger(:namespaces, UPDATE_TRIGGER_NAME)
+ drop_trigger(:namespaces, INSERT_TRIGGER_NAME)
+ drop_function(FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20220513093614_add_ding_talk_into_application_settings.rb b/db/migrate/20220513093614_add_ding_talk_into_application_settings.rb
index 5a34200a3c8..4af8071f564 100644
--- a/db/migrate/20220513093614_add_ding_talk_into_application_settings.rb
+++ b/db/migrate/20220513093614_add_ding_talk_into_application_settings.rb
@@ -2,8 +2,8 @@
class AddDingTalkIntoApplicationSettings < Gitlab::Database::Migration[2.0]
def change
- add_column :application_settings, :dingtalk_integration_enabled, :boolean, null: false,
- default: false, comment: 'JiHu-specific column'
+ add_column :application_settings, :dingtalk_integration_enabled, :boolean,
+ null: false, default: false, comment: 'JiHu-specific column'
add_column :application_settings, :encrypted_dingtalk_corpid, :binary, comment: 'JiHu-specific column'
add_column :application_settings, :encrypted_dingtalk_corpid_iv, :binary, comment: 'JiHu-specific column'
add_column :application_settings, :encrypted_dingtalk_app_key, :binary, comment: 'JiHu-specific column'
diff --git a/db/migrate/20220513093615_add_ding_talk_tracker_data.rb b/db/migrate/20220513093615_add_ding_talk_tracker_data.rb
index 0a9c340fbf0..0289b983a48 100644
--- a/db/migrate/20220513093615_add_ding_talk_tracker_data.rb
+++ b/db/migrate/20220513093615_add_ding_talk_tracker_data.rb
@@ -6,7 +6,7 @@ class AddDingTalkTrackerData < Gitlab::Database::Migration[2.0]
def change
create_table :dingtalk_tracker_data, comment: 'JiHu-specific table' do |t|
t.references :integration, foreign_key: { on_delete: :cascade },
- type: :bigint, index: true, null: false, comment: 'JiHu-specific column'
+ type: :bigint, index: true, null: false, comment: 'JiHu-specific column'
t.timestamps_with_timezone
t.text :corpid, comment: 'JiHu-specific column', limit: 255
t.index :corpid, where: "(corpid IS NOT NULL)", name: INDEX_NAME, comment: 'JiHu-specific index'
diff --git a/db/migrate/20220524184149_create_sync_project_namespace_details_trigger.rb b/db/migrate/20220524184149_create_sync_project_namespace_details_trigger.rb
new file mode 100644
index 00000000000..efce35b443a
--- /dev/null
+++ b/db/migrate/20220524184149_create_sync_project_namespace_details_trigger.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+class CreateSyncProjectNamespaceDetailsTrigger < Gitlab::Database::Migration[2.0]
+ include Gitlab::Database::SchemaHelpers
+
+ UPDATE_TRIGGER_NAME = 'trigger_update_details_on_project_update'
+ INSERT_TRIGGER_NAME = 'trigger_update_details_on_project_insert'
+ FUNCTION_NAME = 'update_namespace_details_from_projects'
+
+ enable_lock_retries!
+
+ def up
+ create_trigger_function(FUNCTION_NAME, replace: true) do
+ <<~SQL
+ INSERT INTO
+ namespace_details (
+ description,
+ description_html,
+ cached_markdown_version,
+ updated_at,
+ created_at,
+ namespace_id
+ )
+ VALUES
+ (
+ NEW.description,
+ NEW.description_html,
+ NEW.cached_markdown_version,
+ NEW.updated_at,
+ NEW.updated_at,
+ NEW.project_namespace_id
+ ) ON CONFLICT (namespace_id) DO
+ UPDATE
+ SET
+ description = NEW.description,
+ description_html = NEW.description_html,
+ cached_markdown_version = NEW.cached_markdown_version,
+ updated_at = NEW.updated_at
+ WHERE
+ namespace_details.namespace_id = NEW.project_namespace_id;RETURN NULL;
+ SQL
+ end
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{UPDATE_TRIGGER_NAME}
+ AFTER UPDATE ON projects
+ FOR EACH ROW
+ WHEN (
+ OLD.description IS DISTINCT FROM NEW.description OR
+ OLD.description_html IS DISTINCT FROM NEW.description_html OR
+ OLD.cached_markdown_version IS DISTINCT FROM NEW.cached_markdown_version
+ )
+ EXECUTE PROCEDURE #{FUNCTION_NAME}();
+ SQL
+
+ execute(<<~SQL)
+ CREATE TRIGGER #{INSERT_TRIGGER_NAME}
+ AFTER INSERT ON projects
+ FOR EACH ROW
+ EXECUTE PROCEDURE #{FUNCTION_NAME}();
+ SQL
+ end
+
+ def down
+ drop_trigger(:projects, UPDATE_TRIGGER_NAME)
+ drop_trigger(:projects, INSERT_TRIGGER_NAME)
+ drop_function(FUNCTION_NAME)
+ end
+end
diff --git a/db/migrate/20220619212618_add_selective_code_owner_removals_to_project_settings.rb b/db/migrate/20220619212618_add_selective_code_owner_removals_to_project_settings.rb
new file mode 100644
index 00000000000..435a1d7a40e
--- /dev/null
+++ b/db/migrate/20220619212618_add_selective_code_owner_removals_to_project_settings.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddSelectiveCodeOwnerRemovalsToProjectSettings < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ add_column :project_settings, :selective_code_owner_removals, :boolean, default: false, null: false
+ end
+end
diff --git a/db/migrate/20220627061008_add_fei_shu_integration.rb b/db/migrate/20220627061008_add_fei_shu_integration.rb
index 8feedc70ce6..6a3bdb0a2e9 100644
--- a/db/migrate/20220627061008_add_fei_shu_integration.rb
+++ b/db/migrate/20220627061008_add_fei_shu_integration.rb
@@ -2,8 +2,8 @@
class AddFeiShuIntegration < Gitlab::Database::Migration[2.0]
def change
- add_column :application_settings, :feishu_integration_enabled, :boolean, null: false,
- default: false, comment: 'JiHu-specific column'
+ add_column :application_settings, :feishu_integration_enabled, :boolean,
+ null: false, default: false, comment: 'JiHu-specific column'
add_column :application_settings, :encrypted_feishu_app_key, :binary, comment: 'JiHu-specific column'
add_column :application_settings, :encrypted_feishu_app_key_iv, :binary, comment: 'JiHu-specific column'
add_column :application_settings, :encrypted_feishu_app_secret, :binary, comment: 'JiHu-specific column'
diff --git a/db/migrate/20220707105335_rename_chat_name_service_id_to_integration_id.rb b/db/migrate/20220707105335_rename_chat_name_service_id_to_integration_id.rb
new file mode 100644
index 00000000000..a6625d030a4
--- /dev/null
+++ b/db/migrate/20220707105335_rename_chat_name_service_id_to_integration_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RenameChatNameServiceIdToIntegrationId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ rename_column_concurrently :chat_names, :service_id, :integration_id
+ end
+
+ def down
+ undo_rename_column_concurrently :chat_names, :service_id, :integration_id
+ end
+end
diff --git a/db/migrate/20220707160707_rename_slack_integration_service_id_to_integration_id.rb b/db/migrate/20220707160707_rename_slack_integration_service_id_to_integration_id.rb
new file mode 100644
index 00000000000..d553e349fc1
--- /dev/null
+++ b/db/migrate/20220707160707_rename_slack_integration_service_id_to_integration_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RenameSlackIntegrationServiceIdToIntegrationId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ rename_column_concurrently :slack_integrations, :service_id, :integration_id
+ end
+
+ def down
+ undo_rename_column_concurrently :slack_integrations, :service_id, :integration_id
+ end
+end
diff --git a/db/migrate/20220707181910_create_member_roles.rb b/db/migrate/20220707181910_create_member_roles.rb
new file mode 100644
index 00000000000..271ec064f08
--- /dev/null
+++ b/db/migrate/20220707181910_create_member_roles.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class CreateMemberRoles < Gitlab::Database::Migration[2.0]
+ def change
+ create_table :member_roles do |t|
+ t.references :namespace,
+ index: true,
+ null: false,
+ foreign_key: { on_delete: :cascade }
+ t.timestamps_with_timezone null: false
+ t.integer :base_access_level, null: false
+ t.boolean :download_code, default: false
+ end
+ end
+end
diff --git a/db/migrate/20220707181920_add_member_role_id_to_members.rb b/db/migrate/20220707181920_add_member_role_id_to_members.rb
new file mode 100644
index 00000000000..f335d2da6f5
--- /dev/null
+++ b/db/migrate/20220707181920_add_member_role_id_to_members.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AddMemberRoleIdToMembers < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def up
+ add_column :members, :member_role_id, :bigint
+ end
+
+ def down
+ remove_column :members, :member_role_id
+ end
+end
diff --git a/db/migrate/20220707181930_add_member_roles_relation_to_members.rb b/db/migrate/20220707181930_add_member_roles_relation_to_members.rb
new file mode 100644
index 00000000000..ede168fe51e
--- /dev/null
+++ b/db/migrate/20220707181930_add_member_roles_relation_to_members.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddMemberRolesRelationToMembers < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+ INDEX_NAME = 'index_members_on_member_role_id'
+
+ def up
+ add_concurrent_index :members, :member_role_id, name: INDEX_NAME
+ add_concurrent_foreign_key :members, :member_roles, column: :member_role_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :members, column: :member_role_id
+ end
+
+ remove_concurrent_index_by_name :members, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20220707190546_add_plan_limits_max_size_cyclonedx_report_column.rb b/db/migrate/20220707190546_add_plan_limits_max_size_cyclonedx_report_column.rb
new file mode 100644
index 00000000000..5ccc6362d2b
--- /dev/null
+++ b/db/migrate/20220707190546_add_plan_limits_max_size_cyclonedx_report_column.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddPlanLimitsMaxSizeCyclonedxReportColumn < Gitlab::Database::Migration[2.0]
+ def change
+ add_column :plan_limits, :ci_max_artifact_size_cyclonedx, :integer, null: false, default: 1
+ end
+end
diff --git a/db/migrate/20220708150315_add_vulnerabilities_foreign_key_to_vulnerability_merge_request_links.rb b/db/migrate/20220708150315_add_vulnerabilities_foreign_key_to_vulnerability_merge_request_links.rb
index f821e2fbe3a..6a1123a2c00 100644
--- a/db/migrate/20220708150315_add_vulnerabilities_foreign_key_to_vulnerability_merge_request_links.rb
+++ b/db/migrate/20220708150315_add_vulnerabilities_foreign_key_to_vulnerability_merge_request_links.rb
@@ -4,8 +4,8 @@ class AddVulnerabilitiesForeignKeyToVulnerabilityMergeRequestLinks < Gitlab::Dat
disable_ddl_transaction!
def up
- add_concurrent_foreign_key :vulnerability_merge_request_links, :vulnerabilities, column: :vulnerability_id,
- on_delete: :cascade
+ add_concurrent_foreign_key :vulnerability_merge_request_links, :vulnerabilities,
+ column: :vulnerability_id, on_delete: :cascade
end
def down
diff --git a/db/migrate/20220708150335_add_merge_requests_foreign_key_to_vulnerability_merge_request_links.rb b/db/migrate/20220708150335_add_merge_requests_foreign_key_to_vulnerability_merge_request_links.rb
index fedda9677f1..af9cef19b75 100644
--- a/db/migrate/20220708150335_add_merge_requests_foreign_key_to_vulnerability_merge_request_links.rb
+++ b/db/migrate/20220708150335_add_merge_requests_foreign_key_to_vulnerability_merge_request_links.rb
@@ -4,8 +4,8 @@ class AddMergeRequestsForeignKeyToVulnerabilityMergeRequestLinks < Gitlab::Datab
disable_ddl_transaction!
def up
- add_concurrent_foreign_key :vulnerability_merge_request_links, :merge_requests, column: :merge_request_id,
- on_delete: :cascade
+ add_concurrent_foreign_key :vulnerability_merge_request_links, :merge_requests, column:
+ :merge_request_id, on_delete: :cascade
end
def down
diff --git a/db/migrate/20220712131513_rename_issue_tracker_data_service_id_to_integration_id.rb b/db/migrate/20220712131513_rename_issue_tracker_data_service_id_to_integration_id.rb
new file mode 100644
index 00000000000..e6a59b66df9
--- /dev/null
+++ b/db/migrate/20220712131513_rename_issue_tracker_data_service_id_to_integration_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RenameIssueTrackerDataServiceIdToIntegrationId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ rename_column_concurrently :issue_tracker_data, :service_id, :integration_id
+ end
+
+ def down
+ undo_rename_column_concurrently :issue_tracker_data, :service_id, :integration_id
+ end
+end
diff --git a/db/migrate/20220712144843_rename_jira_tracker_data_service_id_to_integration_id.rb b/db/migrate/20220712144843_rename_jira_tracker_data_service_id_to_integration_id.rb
new file mode 100644
index 00000000000..5971c68bd93
--- /dev/null
+++ b/db/migrate/20220712144843_rename_jira_tracker_data_service_id_to_integration_id.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class RenameJiraTrackerDataServiceIdToIntegrationId < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ rename_column_concurrently :jira_tracker_data, :service_id, :integration_id
+ end
+
+ def down
+ undo_rename_column_concurrently :jira_tracker_data, :service_id, :integration_id
+ end
+end
diff --git a/db/migrate/20220718083945_add_unique_project_download_limit_allowlist_to_namespace_settings.rb b/db/migrate/20220718083945_add_unique_project_download_limit_allowlist_to_namespace_settings.rb
new file mode 100644
index 00000000000..49d9a652472
--- /dev/null
+++ b/db/migrate/20220718083945_add_unique_project_download_limit_allowlist_to_namespace_settings.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddUniqueProjectDownloadLimitAllowlistToNamespaceSettings < Gitlab::Database::Migration[2.0]
+ def change
+ add_column :namespace_settings, :unique_project_download_limit_allowlist,
+ :text,
+ array: true,
+ default: [],
+ null: false
+ end
+end
diff --git a/db/migrate/20220720161816_add_namespace_id_to_vulnerability_reads_table.rb b/db/migrate/20220720161816_add_namespace_id_to_vulnerability_reads_table.rb
new file mode 100644
index 00000000000..b6af71eb088
--- /dev/null
+++ b/db/migrate/20220720161816_add_namespace_id_to_vulnerability_reads_table.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddNamespaceIdToVulnerabilityReadsTable < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ add_column :vulnerability_reads, :namespace_id, :bigint
+ end
+end
diff --git a/db/migrate/20220720162123_update_vulnerability_reads_triggers_to_set_namespace_id.rb b/db/migrate/20220720162123_update_vulnerability_reads_triggers_to_set_namespace_id.rb
new file mode 100644
index 00000000000..25ecf45bfd5
--- /dev/null
+++ b/db/migrate/20220720162123_update_vulnerability_reads_triggers_to_set_namespace_id.rb
@@ -0,0 +1,159 @@
+# frozen_string_literal: true
+
+class UpdateVulnerabilityReadsTriggersToSetNamespaceId < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def up
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION insert_or_update_vulnerability_reads() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+ DECLARE
+ severity smallint;
+ state smallint;
+ report_type smallint;
+ resolved_on_default_branch boolean;
+ present_on_default_branch boolean;
+ namespace_id bigint;
+ BEGIN
+ IF (NEW.vulnerability_id IS NULL AND (TG_OP = 'INSERT' OR TG_OP = 'UPDATE')) THEN
+ RETURN NULL;
+ END IF;
+
+ IF (TG_OP = 'UPDATE' AND OLD.vulnerability_id IS NOT NULL AND NEW.vulnerability_id IS NOT NULL) THEN
+ RETURN NULL;
+ END IF;
+
+ SELECT
+ vulnerabilities.severity, vulnerabilities.state, vulnerabilities.report_type, vulnerabilities.resolved_on_default_branch, vulnerabilities.present_on_default_branch
+ INTO
+ severity, state, report_type, resolved_on_default_branch, present_on_default_branch
+ FROM
+ vulnerabilities
+ WHERE
+ vulnerabilities.id = NEW.vulnerability_id;
+
+ IF present_on_default_branch IS NOT true THEN
+ RETURN NULL;
+ END IF;
+
+ SELECT
+ projects.namespace_id
+ INTO
+ namespace_id
+ FROM
+ projects
+ WHERE
+ projects.id = NEW.project_id;
+
+ INSERT INTO vulnerability_reads (vulnerability_id, namespace_id, project_id, scanner_id, report_type, severity, state, resolved_on_default_branch, uuid, location_image, cluster_agent_id, casted_cluster_agent_id)
+ VALUES (NEW.vulnerability_id, namespace_id, NEW.project_id, NEW.scanner_id, report_type, severity, state, resolved_on_default_branch, NEW.uuid::uuid, NEW.location->>'image', NEW.location->'kubernetes_resource'->>'agent_id', CAST(NEW.location->'kubernetes_resource'->>'agent_id' AS bigint))
+ ON CONFLICT(vulnerability_id) DO NOTHING;
+ RETURN NULL;
+ END
+ $$;
+ SQL
+
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION insert_vulnerability_reads_from_vulnerability() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+ DECLARE
+ scanner_id bigint;
+ uuid uuid;
+ location_image text;
+ cluster_agent_id text;
+ casted_cluster_agent_id bigint;
+ namespace_id bigint;
+ BEGIN
+ SELECT
+ v_o.scanner_id, v_o.uuid, v_o.location->>'image', v_o.location->'kubernetes_resource'->>'agent_id', CAST(v_o.location->'kubernetes_resource'->>'agent_id' AS bigint), projects.namespace_id
+ INTO
+ scanner_id, uuid, location_image, cluster_agent_id, casted_cluster_agent_id, namespace_id
+ FROM
+ vulnerability_occurrences v_o
+ INNER JOIN projects ON projects.id = v_o.project_id
+ WHERE
+ v_o.vulnerability_id = NEW.id
+ LIMIT 1;
+
+ INSERT INTO vulnerability_reads (vulnerability_id, namespace_id, project_id, scanner_id, report_type, severity, state, resolved_on_default_branch, uuid, location_image, cluster_agent_id, casted_cluster_agent_id)
+ VALUES (NEW.id, namespace_id, NEW.project_id, scanner_id, NEW.report_type, NEW.severity, NEW.state, NEW.resolved_on_default_branch, uuid::uuid, location_image, cluster_agent_id, casted_cluster_agent_id)
+ ON CONFLICT(vulnerability_id) DO NOTHING;
+ RETURN NULL;
+ END
+ $$;
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION insert_or_update_vulnerability_reads() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+ DECLARE
+ severity smallint;
+ state smallint;
+ report_type smallint;
+ resolved_on_default_branch boolean;
+ present_on_default_branch boolean;
+ BEGIN
+ IF (NEW.vulnerability_id IS NULL AND (TG_OP = 'INSERT' OR TG_OP = 'UPDATE')) THEN
+ RETURN NULL;
+ END IF;
+
+ IF (TG_OP = 'UPDATE' AND OLD.vulnerability_id IS NOT NULL AND NEW.vulnerability_id IS NOT NULL) THEN
+ RETURN NULL;
+ END IF;
+
+ SELECT
+ vulnerabilities.severity, vulnerabilities.state, vulnerabilities.report_type, vulnerabilities.resolved_on_default_branch, vulnerabilities.present_on_default_branch
+ INTO
+ severity, state, report_type, resolved_on_default_branch, present_on_default_branch
+ FROM
+ vulnerabilities
+ WHERE
+ vulnerabilities.id = NEW.vulnerability_id;
+
+ IF present_on_default_branch IS NOT true THEN
+ RETURN NULL;
+ END IF;
+
+ INSERT INTO vulnerability_reads (vulnerability_id, project_id, scanner_id, report_type, severity, state, resolved_on_default_branch, uuid, location_image, cluster_agent_id, casted_cluster_agent_id)
+ VALUES (NEW.vulnerability_id, NEW.project_id, NEW.scanner_id, report_type, severity, state, resolved_on_default_branch, NEW.uuid::uuid, NEW.location->>'image', NEW.location->'kubernetes_resource'->>'agent_id', CAST(NEW.location->'kubernetes_resource'->>'agent_id' AS bigint))
+ ON CONFLICT(vulnerability_id) DO NOTHING;
+ RETURN NULL;
+ END
+ $$;
+ SQL
+
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION insert_vulnerability_reads_from_vulnerability() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+ DECLARE
+ scanner_id bigint;
+ uuid uuid;
+ location_image text;
+ cluster_agent_id text;
+ casted_cluster_agent_id bigint;
+ BEGIN
+ SELECT
+ v_o.scanner_id, v_o.uuid, v_o.location->>'image', v_o.location->'kubernetes_resource'->>'agent_id', CAST(v_o.location->'kubernetes_resource'->>'agent_id' AS bigint)
+ INTO
+ scanner_id, uuid, location_image, cluster_agent_id, casted_cluster_agent_id
+ FROM
+ vulnerability_occurrences v_o
+ WHERE
+ v_o.vulnerability_id = NEW.id
+ LIMIT 1;
+
+ INSERT INTO vulnerability_reads (vulnerability_id, project_id, scanner_id, report_type, severity, state, resolved_on_default_branch, uuid, location_image, cluster_agent_id, casted_cluster_agent_id)
+ VALUES (NEW.id, NEW.project_id, scanner_id, NEW.report_type, NEW.severity, NEW.state, NEW.resolved_on_default_branch, uuid::uuid, location_image, cluster_agent_id, casted_cluster_agent_id)
+ ON CONFLICT(vulnerability_id) DO NOTHING;
+ RETURN NULL;
+ END
+ $$;
+ SQL
+ end
+end
diff --git a/db/migrate/20220720210446_add_start_date_to_issues_table.rb b/db/migrate/20220720210446_add_start_date_to_issues_table.rb
new file mode 100644
index 00000000000..315d80fa654
--- /dev/null
+++ b/db/migrate/20220720210446_add_start_date_to_issues_table.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddStartDateToIssuesTable < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ add_column :issues, :start_date, :date
+ end
+end
diff --git a/db/migrate/20220722123318_update_delayed_deletion_period.rb b/db/migrate/20220722123318_update_delayed_deletion_period.rb
new file mode 100644
index 00000000000..4d928a41259
--- /dev/null
+++ b/db/migrate/20220722123318_update_delayed_deletion_period.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class UpdateDelayedDeletionPeriod < Gitlab::Database::Migration[2.0]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ # Before 15.1 the only way to disable delayed deletion was to set
+ # the period to 0, as of 15.1 zero is no longer a valid value (1-90).
+ # This migration sets the period to a valid value and disables
+ # delayed deletion using the delayed_* boolean attributes.
+
+ def up
+ execute <<~SQL
+ UPDATE application_settings SET
+ deletion_adjourned_period = 1,
+ delayed_group_deletion = 'f',
+ delayed_project_removal ='f'
+ WHERE deletion_adjourned_period = 0;
+ SQL
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb b/db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb
new file mode 100644
index 00000000000..d25923923f2
--- /dev/null
+++ b/db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class CreateFunctionGitlabSchemaPreventWrite < Gitlab::Database::Migration[2.0]
+ TRIGGER_FUNCTION_NAME = 'gitlab_schema_prevent_write'
+
+ enable_lock_retries!
+
+ # This migration is only to make sure that the lock-write trigger function
+ # matches what we already have on staging/production for Gitlab.com
+
+ def up
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION #{TRIGGER_FUNCTION_NAME}()
+ RETURNS TRIGGER AS
+ $$
+ BEGIN
+ RAISE EXCEPTION 'Table: "%" is write protected within this Gitlab database.', TG_TABLE_NAME
+ USING ERRCODE = 'modifying_sql_data_not_permitted',
+ HINT = 'Make sure you are using the right database connection';
+ END
+ $$ LANGUAGE PLPGSQL
+ SQL
+ end
+
+ def down
+ return if Gitlab.com?
+
+ execute(<<~SQL)
+ DROP FUNCTION #{TRIGGER_FUNCTION_NAME}
+ SQL
+ end
+end
diff --git a/db/migrate/20220722203840_update_lock_writes_function_disabled_via_setting.rb b/db/migrate/20220722203840_update_lock_writes_function_disabled_via_setting.rb
new file mode 100644
index 00000000000..f78d2b7f155
--- /dev/null
+++ b/db/migrate/20220722203840_update_lock_writes_function_disabled_via_setting.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class UpdateLockWritesFunctionDisabledViaSetting < Gitlab::Database::Migration[2.0]
+ TRIGGER_FUNCTION_NAME = 'gitlab_schema_prevent_write'
+
+ def up
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION #{TRIGGER_FUNCTION_NAME}()
+ RETURNS TRIGGER AS
+ $$
+ BEGIN
+ IF COALESCE(NULLIF(current_setting(CONCAT('lock_writes.', TG_TABLE_NAME), true), ''), 'true') THEN
+ RAISE EXCEPTION 'Table: "%" is write protected within this Gitlab database.', TG_TABLE_NAME
+ USING ERRCODE = 'modifying_sql_data_not_permitted',
+ HINT = 'Make sure you are using the right database connection';
+ END IF;
+ RETURN NEW;
+ END
+ $$ LANGUAGE PLPGSQL;
+ SQL
+ end
+
+ def down
+ execute(<<~SQL)
+ CREATE OR REPLACE FUNCTION #{TRIGGER_FUNCTION_NAME}()
+ RETURNS TRIGGER AS
+ $$
+ BEGIN
+ RAISE EXCEPTION 'Table: "%" is write protected within this Gitlab database.', TG_TABLE_NAME
+ USING ERRCODE = 'modifying_sql_data_not_permitted',
+ HINT = 'Make sure you are using the right database connection';
+ END
+ $$ LANGUAGE PLPGSQL
+ SQL
+ end
+end
diff --git a/db/migrate/20220723120039_add_author_id_to_vulnerability_state_transitions.rb b/db/migrate/20220723120039_add_author_id_to_vulnerability_state_transitions.rb
new file mode 100644
index 00000000000..4b16ba2bb82
--- /dev/null
+++ b/db/migrate/20220723120039_add_author_id_to_vulnerability_state_transitions.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddAuthorIdToVulnerabilityStateTransitions < Gitlab::Database::Migration[2.0]
+ def change
+ add_column :vulnerability_state_transitions, :author_id, :bigint
+ end
+end
diff --git a/db/migrate/20220726025516_add_namespace_settings_unique_project_download_limit_allowlist_size_constraint.rb b/db/migrate/20220726025516_add_namespace_settings_unique_project_download_limit_allowlist_size_constraint.rb
new file mode 100644
index 00000000000..bded83f7941
--- /dev/null
+++ b/db/migrate/20220726025516_add_namespace_settings_unique_project_download_limit_allowlist_size_constraint.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddNamespaceSettingsUniqueProjectDownloadLimitAllowlistSizeConstraint < Gitlab::Database::Migration[2.0]
+ CONSTRAINT_NAME = 'namespace_settings_unique_project_download_limit_allowlist_size'
+
+ disable_ddl_transaction!
+
+ def up
+ add_check_constraint :namespace_settings,
+ 'CARDINALITY(unique_project_download_limit_allowlist) <= 100',
+ CONSTRAINT_NAME
+ end
+
+ def down
+ remove_check_constraint :namespace_settings, CONSTRAINT_NAME
+ end
+end
diff --git a/db/migrate/20220726154012_ensure_sbom_occurrences_is_empty.rb b/db/migrate/20220726154012_ensure_sbom_occurrences_is_empty.rb
new file mode 100644
index 00000000000..18c48d1202d
--- /dev/null
+++ b/db/migrate/20220726154012_ensure_sbom_occurrences_is_empty.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class EnsureSbomOccurrencesIsEmpty < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ def up
+ # Ensure that the sbom_occurrences table is empty to ensure that the
+ # following migration adding a not-null column succeeds.
+ # The code which creates records in this table has not been implemented yet.
+ execute('DELETE FROM sbom_occurrences')
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/migrate/20220726154013_add_component_id_to_sbom_occurrences.rb b/db/migrate/20220726154013_add_component_id_to_sbom_occurrences.rb
new file mode 100644
index 00000000000..9631dadc938
--- /dev/null
+++ b/db/migrate/20220726154013_add_component_id_to_sbom_occurrences.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddComponentIdToSbomOccurrences < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def up
+ # Code using this table has not been implemented yet.
+ # The migration prior to this one ensures that it is empty.
+ # rubocop:disable Rails/NotNullColumn
+ add_column :sbom_occurrences, :component_id, :bigint, null: false
+ # rubocop:enable Rails/NotNullColumn
+ end
+
+ def down
+ remove_column :sbom_occurrences, :component_id
+ end
+end
diff --git a/db/migrate/20220726154014_add_index_to_sbom_occurrences_component_id.rb b/db/migrate/20220726154014_add_index_to_sbom_occurrences_component_id.rb
new file mode 100644
index 00000000000..ed944fd0b90
--- /dev/null
+++ b/db/migrate/20220726154014_add_index_to_sbom_occurrences_component_id.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddIndexToSbomOccurrencesComponentId < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = "index_sbom_occurrences_on_component_id"
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :sbom_occurrences, :component_id, name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :sbom_occurrences, name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20220726154015_add_component_foreign_key_to_sbom_occurrences.rb b/db/migrate/20220726154015_add_component_foreign_key_to_sbom_occurrences.rb
new file mode 100644
index 00000000000..1c7341c4aa2
--- /dev/null
+++ b/db/migrate/20220726154015_add_component_foreign_key_to_sbom_occurrences.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddComponentForeignKeyToSbomOccurrences < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :sbom_occurrences,
+ :sbom_components,
+ column: :component_id,
+ on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :sbom_occurrences, column: :component_id
+ end
+ end
+end
diff --git a/db/migrate/20220726154016_make_component_version_nullable.rb b/db/migrate/20220726154016_make_component_version_nullable.rb
new file mode 100644
index 00000000000..8619b9dad12
--- /dev/null
+++ b/db/migrate/20220726154016_make_component_version_nullable.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class MakeComponentVersionNullable < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ change_column_null :sbom_occurrences, :component_version_id, true
+ end
+end
diff --git a/db/migrate/20220726230052_remove_tmp_index_project_membership_namespace_id_column.rb b/db/migrate/20220726230052_remove_tmp_index_project_membership_namespace_id_column.rb
new file mode 100644
index 00000000000..e50665c106b
--- /dev/null
+++ b/db/migrate/20220726230052_remove_tmp_index_project_membership_namespace_id_column.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class RemoveTmpIndexProjectMembershipNamespaceIdColumn < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'tmp_index_for_namespace_id_migration_on_project_members'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :members, INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :members, :id,
+ where: "members.member_namespace_id IS NULL and members.type = 'ProjectMember'",
+ name: INDEX_NAME
+ end
+end
diff --git a/db/migrate/20220728114136_make_ssh_signature_key_nullable.rb b/db/migrate/20220728114136_make_ssh_signature_key_nullable.rb
new file mode 100644
index 00000000000..5d724e9f406
--- /dev/null
+++ b/db/migrate/20220728114136_make_ssh_signature_key_nullable.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class MakeSshSignatureKeyNullable < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ change_column_null :ssh_signatures, :key_id, true
+ end
+end
diff --git a/db/migrate/20220729073603_index_personal_access_tokens_on_id_and_created_at.rb b/db/migrate/20220729073603_index_personal_access_tokens_on_id_and_created_at.rb
new file mode 100644
index 00000000000..b865f76fec1
--- /dev/null
+++ b/db/migrate/20220729073603_index_personal_access_tokens_on_id_and_created_at.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class IndexPersonalAccessTokensOnIdAndCreatedAt < Gitlab::Database::Migration[2.0]
+ INDEX_NAME = 'index_personal_access_tokens_on_id_and_created_at'
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :personal_access_tokens, [:id, :created_at], name: INDEX_NAME
+ end
+
+ def down
+ remove_concurrent_index_by_name :personal_access_tokens, INDEX_NAME
+ end
+end
diff --git a/db/migrate/20220802154757_add_deactivate_dormant_user_time_setting.rb b/db/migrate/20220802154757_add_deactivate_dormant_user_time_setting.rb
new file mode 100644
index 00000000000..ca887cc2255
--- /dev/null
+++ b/db/migrate/20220802154757_add_deactivate_dormant_user_time_setting.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+class AddDeactivateDormantUserTimeSetting < Gitlab::Database::Migration[2.0]
+ def change
+ add_column :application_settings, :deactivate_dormant_users_period, :integer, default: 90, null: false
+ end
+end
diff --git a/db/migrate/20220803145637_create_user_project_callout.rb b/db/migrate/20220803145637_create_user_project_callout.rb
new file mode 100644
index 00000000000..1d0baf741a9
--- /dev/null
+++ b/db/migrate/20220803145637_create_user_project_callout.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class CreateUserProjectCallout < Gitlab::Database::Migration[2.0]
+ def up
+ create_table :user_project_callouts do |t|
+ t.bigint :user_id, null: false
+ t.bigint :project_id, null: false
+ t.integer :feature_name, limit: 2, null: false
+ t.datetime_with_timezone :dismissed_at
+
+ t.index :project_id
+ t.index [:user_id, :feature_name, :project_id], unique: true, name: 'index_project_user_callouts_feature'
+ end
+ end
+
+ def down
+ drop_table :user_project_callouts
+ end
+end
diff --git a/db/migrate/20220803154543_add_project_id_fkey_for_user_project_callout.rb b/db/migrate/20220803154543_add_project_id_fkey_for_user_project_callout.rb
new file mode 100644
index 00000000000..3cea53dc127
--- /dev/null
+++ b/db/migrate/20220803154543_add_project_id_fkey_for_user_project_callout.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddProjectIdFkeyForUserProjectCallout < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :user_project_callouts, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :user_project_callouts, column: :project_id
+ end
+ end
+end
diff --git a/db/migrate/20220803154758_add_user_id_fkey_for_user_project_callout.rb b/db/migrate/20220803154758_add_user_id_fkey_for_user_project_callout.rb
new file mode 100644
index 00000000000..01a05f816da
--- /dev/null
+++ b/db/migrate/20220803154758_add_user_id_fkey_for_user_project_callout.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddUserIdFkeyForUserProjectCallout < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :user_project_callouts, :users, column: :user_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :user_project_callouts, column: :user_id
+ end
+ end
+end
diff --git a/db/migrate/20220805154101_add_allow_run_pipelines_in_the_parent_project_setting.rb b/db/migrate/20220805154101_add_allow_run_pipelines_in_the_parent_project_setting.rb
new file mode 100644
index 00000000000..dbc76e8ccfd
--- /dev/null
+++ b/db/migrate/20220805154101_add_allow_run_pipelines_in_the_parent_project_setting.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class AddAllowRunPipelinesInTheParentProjectSetting < Gitlab::Database::Migration[2.0]
+ def change
+ add_column :project_ci_cd_settings, :allow_fork_pipelines_to_run_in_parent_project, :boolean,
+ default: true, null: false
+ end
+end
diff --git a/db/migrate/20220808133824_add_timestamps_to_project_statistics.rb b/db/migrate/20220808133824_add_timestamps_to_project_statistics.rb
new file mode 100644
index 00000000000..c5125ebc8ff
--- /dev/null
+++ b/db/migrate/20220808133824_add_timestamps_to_project_statistics.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddTimestampsToProjectStatistics < Gitlab::Database::Migration[2.0]
+ def change
+ add_timestamps_with_timezone(:project_statistics, null: false, default: -> { 'NOW()' })
+ end
+end
diff --git a/db/migrate/20220808190124_add_id_token_to_ci_builds_metadata.rb b/db/migrate/20220808190124_add_id_token_to_ci_builds_metadata.rb
new file mode 100644
index 00000000000..00d27d7c516
--- /dev/null
+++ b/db/migrate/20220808190124_add_id_token_to_ci_builds_metadata.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddIdTokenToCiBuildsMetadata < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ add_column :ci_builds_metadata, :id_tokens, :jsonb, null: false, default: {}
+ end
+end
diff --git a/db/migrate/20220808194857_remove_description_html_limit.rb b/db/migrate/20220808194857_remove_description_html_limit.rb
new file mode 100644
index 00000000000..f7444594566
--- /dev/null
+++ b/db/migrate/20220808194857_remove_description_html_limit.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveDescriptionHtmlLimit < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ remove_text_limit :namespace_details, :description_html
+ remove_text_limit :namespace_details, :description
+ end
+
+ def down
+ add_text_limit :namespace_details, :description_html, 255
+ add_text_limit :namespace_details, :description, 255
+ end
+end
diff --git a/db/migrate/20220811092243_create_ml_experiments.rb b/db/migrate/20220811092243_create_ml_experiments.rb
new file mode 100644
index 00000000000..a357d62133c
--- /dev/null
+++ b/db/migrate/20220811092243_create_ml_experiments.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class CreateMlExperiments < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ create_table :ml_experiments do |t|
+ t.timestamps_with_timezone null: false
+ t.bigint :iid, null: false
+ t.bigint :project_id, null: false
+ t.references :user, foreign_key: true, index: true, on_delete: :nullify
+ t.text :name, limit: 255, null: false
+
+ t.index [:project_id, :iid], unique: true
+ t.index [:project_id, :name], unique: true
+ end
+ end
+end
diff --git a/db/migrate/20220811092244_create_ml_candidates.rb b/db/migrate/20220811092244_create_ml_candidates.rb
new file mode 100644
index 00000000000..fe9fc293b03
--- /dev/null
+++ b/db/migrate/20220811092244_create_ml_candidates.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateMlCandidates < Gitlab::Database::Migration[2.0]
+ enable_lock_retries!
+
+ def change
+ create_table :ml_candidates do |t|
+ t.timestamps_with_timezone null: false
+ t.uuid :iid, null: false
+ t.bigint :experiment_id, null: false
+ t.references :user, foreign_key: true, index: true, on_delete: :nullify
+
+ t.index [:experiment_id, :iid], unique: true
+ end
+ end
+end
diff --git a/db/migrate/20220811092245_create_ml_candidate_params.rb b/db/migrate/20220811092245_create_ml_candidate_params.rb
new file mode 100644
index 00000000000..55fc1cbe7af
--- /dev/null
+++ b/db/migrate/20220811092245_create_ml_candidate_params.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class CreateMlCandidateParams < Gitlab::Database::Migration[2.0]
+ def change
+ create_table :ml_candidate_params do |t|
+ t.timestamps_with_timezone null: false
+ t.references :candidate,
+ foreign_key: { to_table: :ml_candidates },
+ index: true
+ t.text :name, limit: 250, null: false
+ t.text :value, limit: 250, null: false
+ end
+ end
+end
diff --git a/db/migrate/20220811092246_create_ml_candidate_metrics.rb b/db/migrate/20220811092246_create_ml_candidate_metrics.rb
new file mode 100644
index 00000000000..a4d417f270e
--- /dev/null
+++ b/db/migrate/20220811092246_create_ml_candidate_metrics.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class CreateMlCandidateMetrics < Gitlab::Database::Migration[2.0]
+ def change
+ create_table :ml_candidate_metrics do |t|
+ t.timestamps_with_timezone null: false
+ t.references :candidate,
+ foreign_key: { to_table: :ml_candidates },
+ index: true
+ t.float :value
+ t.integer :step
+ t.binary :is_nan
+ t.text :name, limit: 250, null: false
+ end
+ end
+end
diff --git a/db/migrate/20220811092251_add_ml_candidates_reference_to_experiment.rb b/db/migrate/20220811092251_add_ml_candidates_reference_to_experiment.rb
new file mode 100644
index 00000000000..a3be644552c
--- /dev/null
+++ b/db/migrate/20220811092251_add_ml_candidates_reference_to_experiment.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddMlCandidatesReferenceToExperiment < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ml_candidates, :ml_experiments, column: :experiment_id
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :ml_candidates, column: :experiment_id
+ end
+ end
+end
diff --git a/db/migrate/20220811092253_add_ml_experiments_reference_to_project.rb b/db/migrate/20220811092253_add_ml_experiments_reference_to_project.rb
new file mode 100644
index 00000000000..4fd832dfe14
--- /dev/null
+++ b/db/migrate/20220811092253_add_ml_experiments_reference_to_project.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class AddMlExperimentsReferenceToProject < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_foreign_key :ml_experiments, :projects, column: :project_id, on_delete: :cascade
+ end
+
+ def down
+ with_lock_retries do
+ remove_foreign_key :ml_experiments, column: :project_id
+ end
+ end
+end