From 7e9c479f7de77702622631cff2628a9c8dcbc627 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 19 Nov 2020 08:27:35 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-6-stable-ee --- ...8212414_add_feature_flag_events_to_web_hooks.rb | 9 ++++ ...licy_worker_settings_to_application_settings.rb | 19 ++++++++ ...icy_cleanup_status_to_container_repositories.rb | 26 ++++++++++ ...d_ci_jwt_signing_key_to_application_settings.rb | 13 +++++ ...ion_settings_encrypted_ci_jwt_signing_key_iv.rb | 17 +++++++ .../20201008013434_generate_ci_jwt_signing_key.rb | 32 +++++++++++++ ...01008075620_add_releases_events_to_web_hooks.rb | 9 ++++ .../20201008125643_create_csv_issue_imports.rb | 18 +++++++ ...ex_defaults_on_container_expiration_policies.rb | 21 +++++++++ ...08224441_add_position_into_security_findings.rb | 19 ++++++++ ...3022_remove_not_null_constraint_on_framework.rb | 33 +++++++++++++ ...piration_policies_worker_capacity_constraint.rb | 22 +++++++++ db/migrate/20201012134230_create_ci_test_cases.rb | 27 +++++++++++ .../20201012135330_create_ci_test_case_failures.rb | 22 +++++++++ ...01012140110_add_projects_fk_to_ci_test_cases.rb | 19 ++++++++ ...52_add_ci_builds_fk_to_ci_test_case_failures.rb | 19 ++++++++ ...1014163633_specify_primary_key_where_missing.rb | 46 ++++++++++++++++++ ...add_project_foreign_key_to_csv_issue_imports.rb | 19 ++++++++ ...25_add_user_foreign_key_to_csv_issue_imports.rb | 19 ++++++++ ...add_index_on_state_for_dast_site_validations.rb | 22 +++++++++ ..._add_ci_build_id_to_terraform_state_versions.rb | 28 +++++++++++ ..._project_id_and_id_to_container_repositories.rb | 18 +++++++ ...on_scan_id_and_position_of_security_findings.rb | 18 +++++++ ...01019101549_add_es_custom_analyzers_settings.rb | 12 +++++ ...dd_sha256_and_filecount_to_pages_deployments.rb | 22 +++++++++ ...new_user_signups_cap_to_application_settings.rb | 9 ++++ ...9130244_remove_license_compliance_temp_index.rb | 18 +++++++ ...lt_branch_to_daily_build_group_report_result.rb | 11 +++++ .../20201019161924_add_partitioned_table_view.rb | 44 +++++++++++++++++ db/migrate/20201019172704_add_partitions_view.rb | 39 +++++++++++++++ ...07_create_analytics_devops_adoption_segments.rb | 24 ++++++++++ ...956_add_index_route_on_name_trigram_to_route.rb | 18 +++++++ ...analytics_devops_adoption_segment_selections.rb | 17 +++++++ ..._foreign_key_project_id_to_segment_selection.rb | 19 ++++++++ ...dd_foreign_key_group_id_to_segment_selection.rb | 19 ++++++++ ...59_add_check_constraint_to_segment_selection.rb | 19 ++++++++ ...index_to_ci_daily_build_group_report_results.rb | 24 ++++++++++ ...ection_token_revocation_application_settings.rb | 21 +++++++++ ...ection_token_revocation_application_settings.rb | 17 +++++++ .../20201021220101_add_merge_trains_enabled.rb | 9 ++++ ...2080802_add_repository_read_only_to_snippets.rb | 9 ++++ ...201022094845_add_historical_data_recorded_at.rb | 13 +++++ ...022094846_update_historical_data_recorded_at.rb | 31 ++++++++++++ ...1022103304_add_availability_to_user_statuses.rb | 9 ++++ ...44501_create_snippet_repository_storage_move.rb | 32 +++++++++++++ ...dd_has_vulnerabilities_into_project_settings.rb | 19 ++++++++ ...dex_project_settings_on_project_id_partially.rb | 18 +++++++ ...14628_create_merge_request_cleanup_schedules.rb | 27 +++++++++++ .../20201026200736_seed_merge_trains_enabled.rb | 19 ++++++++ ...002551_migrate_services_to_http_integrations.rb | 51 ++++++++++++++++++++ .../20201027135651_add_auto_rollback_setting.rb | 19 ++++++++ ...dex_to_oauth_access_grants_resource_owner_id.rb | 18 +++++++ ...211138_increase_default_diff_max_patch_bytes.rb | 9 ++++ ...add_temporary_index_to_vulnerabilities_table.rb | 18 +++++++ ...028184640_add_helm_major_version_to_clusters.rb | 12 +++++ ...efault_diff_max_patch_bytes_to_minimum_200kb.rb | 20 ++++++++ ...ame_application_settings_to_allow_deny_names.rb | 21 +++++++++ ...029144444_create_vulnerability_finding_links.rb | 25 ++++++++++ ...equirements_access_level_to_project_features.rb | 19 ++++++++ ...30200115_add_iid_to_design_management_design.rb | 9 ++++ ..._on_design_management_designs_iid_project_id.rb | 21 +++++++++ ...to_incident_issues_on_project_and_created_at.rb | 30 ++++++++++++ .../20201103095752_add_issues_closed_at_index.rb | 17 +++++++ ...1537_add_index_active_billable_users_to_user.rb | 21 +++++++++ ...333_create_packages_package_file_build_infos.rb | 30 ++++++++++++ ...1103202213_update_packages_build_infos_index.rb | 22 +++++++++ .../20201104204739_create_bulk_import_trackers.rb | 42 +++++++++++++++++ ...21637_add_uploads_size_to_project_statistics.rb | 13 +++++ ...ds_size_to_namespace_root_storage_statistics.rb | 13 +++++ ...tifact_size_lsif_of_plan_limits_from20_to100.rb | 21 +++++++++ ...s_enabled_and_issuetype_to_jira_tracker_data.rb | 13 +++++ ...dd_text_limit_to_jira_tracker_data_issuetype.rb | 17 +++++++ .../20201106134139_add_pipelines_created_index.rb | 19 ++++++++ ...al_after_user_signup_to_application_settings.rb | 9 ++++ .../20201109144634_add_region_field_to_aws_role.rb | 21 +++++++++ ..._revocation_token_types_application_settings.rb | 13 +++++ ..._revocation_token_types_application_settings.rb | 17 +++++++ ...erability_occurrences_on_project_fingerprint.rb | 18 +++++++ .../20201110110454_extend_postgres_indexes_view.rb | 55 ++++++++++++++++++++++ ...29_change_index_mr_metrics_target_project_id.rb | 20 ++++++++ ...318_add_cloud_license_auth_token_to_settings.rb | 13 +++++ ...e_auth_token_application_settings_text_limit.rb | 17 +++++++ ...0201111152859_add_missing_expression_indexes.rb | 43 +++++++++++++++++ .../20201112195322_reseed_merge_trains_enabled.rb | 19 ++++++++ 84 files changed, 1759 insertions(+) create mode 100644 db/migrate/20200908212414_add_feature_flag_events_to_web_hooks.rb create mode 100644 db/migrate/20200920130356_add_container_expiration_policy_worker_settings_to_application_settings.rb create mode 100644 db/migrate/20200928123510_add_expiration_policy_cleanup_status_to_container_repositories.rb create mode 100644 db/migrate/20201008011523_add_ci_jwt_signing_key_to_application_settings.rb create mode 100644 db/migrate/20201008011937_add_text_limit_to_application_settings_encrypted_ci_jwt_signing_key_iv.rb create mode 100644 db/migrate/20201008013434_generate_ci_jwt_signing_key.rb create mode 100644 db/migrate/20201008075620_add_releases_events_to_web_hooks.rb create mode 100644 db/migrate/20201008125643_create_csv_issue_imports.rb create mode 100644 db/migrate/20201008144854_set_regex_defaults_on_container_expiration_policies.rb create mode 100644 db/migrate/20201008224441_add_position_into_security_findings.rb create mode 100644 db/migrate/20201012073022_remove_not_null_constraint_on_framework.rb create mode 100644 db/migrate/20201012122428_add_container_registry_expiration_policies_worker_capacity_constraint.rb create mode 100644 db/migrate/20201012134230_create_ci_test_cases.rb create mode 100644 db/migrate/20201012135330_create_ci_test_case_failures.rb create mode 100644 db/migrate/20201012140110_add_projects_fk_to_ci_test_cases.rb create mode 100644 db/migrate/20201012140452_add_ci_builds_fk_to_ci_test_case_failures.rb create mode 100644 db/migrate/20201014163633_specify_primary_key_where_missing.rb create mode 100644 db/migrate/20201015121805_add_project_foreign_key_to_csv_issue_imports.rb create mode 100644 db/migrate/20201015121825_add_user_foreign_key_to_csv_issue_imports.rb create mode 100644 db/migrate/20201015194852_add_index_on_state_for_dast_site_validations.rb create mode 100644 db/migrate/20201015231049_add_ci_build_id_to_terraform_state_versions.rb create mode 100644 db/migrate/20201016074302_add_index_project_id_and_id_to_container_repositories.rb create mode 100644 db/migrate/20201019091307_add_unique_index_on_scan_id_and_position_of_security_findings.rb create mode 100644 db/migrate/20201019101549_add_es_custom_analyzers_settings.rb create mode 100644 db/migrate/20201019111952_add_sha256_and_filecount_to_pages_deployments.rb create mode 100644 db/migrate/20201019113009_add_new_user_signups_cap_to_application_settings.rb create mode 100644 db/migrate/20201019130244_remove_license_compliance_temp_index.rb create mode 100644 db/migrate/20201019152046_add_default_branch_to_daily_build_group_report_result.rb create mode 100644 db/migrate/20201019161924_add_partitioned_table_view.rb create mode 100644 db/migrate/20201019172704_add_partitions_view.rb create mode 100644 db/migrate/20201021085007_create_analytics_devops_adoption_segments.rb create mode 100644 db/migrate/20201021101956_add_index_route_on_name_trigram_to_route.rb create mode 100644 db/migrate/20201021102554_create_analytics_devops_adoption_segment_selections.rb create mode 100644 db/migrate/20201021105347_add_foreign_key_project_id_to_segment_selection.rb create mode 100644 db/migrate/20201021105600_add_foreign_key_group_id_to_segment_selection.rb create mode 100644 db/migrate/20201021105959_add_check_constraint_to_segment_selection.rb create mode 100644 db/migrate/20201021142812_add_index_to_ci_daily_build_group_report_results.rb create mode 100644 db/migrate/20201021152210_add_secret_detection_token_revocation_application_settings.rb create mode 100644 db/migrate/20201021190539_add_text_limit_to_secret_detection_token_revocation_application_settings.rb create mode 100644 db/migrate/20201021220101_add_merge_trains_enabled.rb create mode 100644 db/migrate/20201022080802_add_repository_read_only_to_snippets.rb create mode 100644 db/migrate/20201022094845_add_historical_data_recorded_at.rb create mode 100644 db/migrate/20201022094846_update_historical_data_recorded_at.rb create mode 100644 db/migrate/20201022103304_add_availability_to_user_statuses.rb create mode 100644 db/migrate/20201022144501_create_snippet_repository_storage_move.rb create mode 100644 db/migrate/20201022191817_add_has_vulnerabilities_into_project_settings.rb create mode 100644 db/migrate/20201022192254_index_project_settings_on_project_id_partially.rb create mode 100644 db/migrate/20201023114628_create_merge_request_cleanup_schedules.rb create mode 100644 db/migrate/20201026200736_seed_merge_trains_enabled.rb create mode 100644 db/migrate/20201027002551_migrate_services_to_http_integrations.rb create mode 100644 db/migrate/20201027135651_add_auto_rollback_setting.rb create mode 100644 db/migrate/20201027210127_add_index_to_oauth_access_grants_resource_owner_id.rb create mode 100644 db/migrate/20201027211138_increase_default_diff_max_patch_bytes.rb create mode 100644 db/migrate/20201028160831_add_temporary_index_to_vulnerabilities_table.rb create mode 100644 db/migrate/20201028184640_add_helm_major_version_to_clusters.rb create mode 100644 db/migrate/20201028204306_migrate_default_diff_max_patch_bytes_to_minimum_200kb.rb create mode 100644 db/migrate/20201029143650_rename_application_settings_to_allow_deny_names.rb create mode 100644 db/migrate/20201029144444_create_vulnerability_finding_links.rb create mode 100644 db/migrate/20201030092151_add_requirements_access_level_to_project_features.rb create mode 100644 db/migrate/20201030200115_add_iid_to_design_management_design.rb create mode 100644 db/migrate/20201030200539_add_index_on_design_management_designs_iid_project_id.rb create mode 100644 db/migrate/20201102184743_add_index_to_incident_issues_on_project_and_created_at.rb create mode 100644 db/migrate/20201103095752_add_issues_closed_at_index.rb create mode 100644 db/migrate/20201103171537_add_index_active_billable_users_to_user.rb create mode 100644 db/migrate/20201103184333_create_packages_package_file_build_infos.rb create mode 100644 db/migrate/20201103202213_update_packages_build_infos_index.rb create mode 100644 db/migrate/20201104204739_create_bulk_import_trackers.rb create mode 100644 db/migrate/20201105021637_add_uploads_size_to_project_statistics.rb create mode 100644 db/migrate/20201105024127_add_uploads_size_to_namespace_root_storage_statistics.rb create mode 100644 db/migrate/20201105135051_change_default_value_of_ci_max_artifact_size_lsif_of_plan_limits_from20_to100.rb create mode 100644 db/migrate/20201105143211_add_vulnerabilities_enabled_and_issuetype_to_jira_tracker_data.rb create mode 100644 db/migrate/20201105143312_add_text_limit_to_jira_tracker_data_issuetype.rb create mode 100644 db/migrate/20201106134139_add_pipelines_created_index.rb create mode 100644 db/migrate/20201107032257_add_default_true_require_admin_approval_after_user_signup_to_application_settings.rb create mode 100644 db/migrate/20201109144634_add_region_field_to_aws_role.rb create mode 100644 db/migrate/20201109180311_add_secret_detection_revocation_token_types_application_settings.rb create mode 100644 db/migrate/20201109184023_add_text_limit_to_secret_detection_revocation_token_types_application_settings.rb create mode 100644 db/migrate/20201110035029_created_index_for_vulnerability_occurrences_on_project_fingerprint.rb create mode 100644 db/migrate/20201110110454_extend_postgres_indexes_view.rb create mode 100644 db/migrate/20201110133629_change_index_mr_metrics_target_project_id.rb create mode 100644 db/migrate/20201111110318_add_cloud_license_auth_token_to_settings.rb create mode 100644 db/migrate/20201111110918_add_cloud_license_auth_token_application_settings_text_limit.rb create mode 100644 db/migrate/20201111152859_add_missing_expression_indexes.rb create mode 100644 db/migrate/20201112195322_reseed_merge_trains_enabled.rb (limited to 'db/migrate') diff --git a/db/migrate/20200908212414_add_feature_flag_events_to_web_hooks.rb b/db/migrate/20200908212414_add_feature_flag_events_to_web_hooks.rb new file mode 100644 index 00000000000..40e2b37b390 --- /dev/null +++ b/db/migrate/20200908212414_add_feature_flag_events_to_web_hooks.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddFeatureFlagEventsToWebHooks < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :web_hooks, :feature_flag_events, :boolean, null: false, default: false + end +end diff --git a/db/migrate/20200920130356_add_container_expiration_policy_worker_settings_to_application_settings.rb b/db/migrate/20200920130356_add_container_expiration_policy_worker_settings_to_application_settings.rb new file mode 100644 index 00000000000..7501f150283 --- /dev/null +++ b/db/migrate/20200920130356_add_container_expiration_policy_worker_settings_to_application_settings.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddContainerExpirationPolicyWorkerSettingsToApplicationSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + unless column_exists?(:application_settings, :container_registry_expiration_policies_worker_capacity) + add_column(:application_settings, :container_registry_expiration_policies_worker_capacity, :integer, default: 0, null: false) + end + end + + def down + if column_exists?(:application_settings, :container_registry_expiration_policies_worker_capacity) + remove_column(:application_settings, :container_registry_expiration_policies_worker_capacity) + end + end +end diff --git a/db/migrate/20200928123510_add_expiration_policy_cleanup_status_to_container_repositories.rb b/db/migrate/20200928123510_add_expiration_policy_cleanup_status_to_container_repositories.rb new file mode 100644 index 00000000000..4d611a56e9c --- /dev/null +++ b/db/migrate/20200928123510_add_expiration_policy_cleanup_status_to_container_repositories.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class AddExpirationPolicyCleanupStatusToContainerRepositories < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'idx_container_repositories_on_exp_cleanup_status_and_start_date' + + disable_ddl_transaction! + + def up + unless column_exists?(:container_repositories, :expiration_policy_cleanup_status) + add_column(:container_repositories, :expiration_policy_cleanup_status, :integer, limit: 2, default: 0, null: false) + end + + add_concurrent_index(:container_repositories, [:expiration_policy_cleanup_status, :expiration_policy_started_at], name: INDEX_NAME) + end + + def down + remove_concurrent_index(:container_repositories, [:expiration_policy_cleanup_status, :expiration_policy_started_at], name: INDEX_NAME) + + if column_exists?(:container_repositories, :expiration_policy_cleanup_status) + remove_column(:container_repositories, :expiration_policy_cleanup_status) + end + end +end diff --git a/db/migrate/20201008011523_add_ci_jwt_signing_key_to_application_settings.rb b/db/migrate/20201008011523_add_ci_jwt_signing_key_to_application_settings.rb new file mode 100644 index 00000000000..c51f7e8b706 --- /dev/null +++ b/db/migrate/20201008011523_add_ci_jwt_signing_key_to_application_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddCiJwtSigningKeyToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20201001011937_add_text_limit_to_application_settings_encrypted_ci_jwt_signing_key_iv + def change + add_column :application_settings, :encrypted_ci_jwt_signing_key, :text + add_column :application_settings, :encrypted_ci_jwt_signing_key_iv, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20201008011937_add_text_limit_to_application_settings_encrypted_ci_jwt_signing_key_iv.rb b/db/migrate/20201008011937_add_text_limit_to_application_settings_encrypted_ci_jwt_signing_key_iv.rb new file mode 100644 index 00000000000..39f6eb2106a --- /dev/null +++ b/db/migrate/20201008011937_add_text_limit_to_application_settings_encrypted_ci_jwt_signing_key_iv.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTextLimitToApplicationSettingsEncryptedCiJwtSigningKeyIv < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :encrypted_ci_jwt_signing_key_iv, 255 + end + + def down + remove_text_limit :application_settings, :encrypted_ci_jwt_signing_key_iv + end +end diff --git a/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb b/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb new file mode 100644 index 00000000000..7983a56f439 --- /dev/null +++ b/db/migrate/20201008013434_generate_ci_jwt_signing_key.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class GenerateCiJwtSigningKey < ActiveRecord::Migration[6.0] + DOWNTIME = false + + class ApplicationSetting < ActiveRecord::Base + self.table_name = 'application_settings' + + attr_encrypted :ci_jwt_signing_key, { + mode: :per_attribute_iv, + key: Rails.application.secrets.db_key_base[0..31], + algorithm: 'aes-256-gcm', + encode: true + } + end + + def up + ApplicationSetting.reset_column_information + + ApplicationSetting.find_each do |application_setting| + application_setting.update(ci_jwt_signing_key: OpenSSL::PKey::RSA.new(2048).to_pem) + end + end + + def down + ApplicationSetting.reset_column_information + + ApplicationSetting.find_each do |application_setting| + application_setting.update_columns(encrypted_ci_jwt_signing_key: nil, encrypted_ci_jwt_signing_key_iv: nil) + end + end +end diff --git a/db/migrate/20201008075620_add_releases_events_to_web_hooks.rb b/db/migrate/20201008075620_add_releases_events_to_web_hooks.rb new file mode 100644 index 00000000000..f6df213f162 --- /dev/null +++ b/db/migrate/20201008075620_add_releases_events_to_web_hooks.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddReleasesEventsToWebHooks < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :web_hooks, :releases_events, :boolean, null: false, default: false + end +end diff --git a/db/migrate/20201008125643_create_csv_issue_imports.rb b/db/migrate/20201008125643_create_csv_issue_imports.rb new file mode 100644 index 00000000000..be3206af6d8 --- /dev/null +++ b/db/migrate/20201008125643_create_csv_issue_imports.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateCsvIssueImports < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + create_table :csv_issue_imports do |t| + t.bigint :project_id, null: false, index: true + t.bigint :user_id, null: false, index: true + + t.timestamps_with_timezone + end + end + + def down + drop_table :csv_issue_imports + end +end diff --git a/db/migrate/20201008144854_set_regex_defaults_on_container_expiration_policies.rb b/db/migrate/20201008144854_set_regex_defaults_on_container_expiration_policies.rb new file mode 100644 index 00000000000..45c411fc238 --- /dev/null +++ b/db/migrate/20201008144854_set_regex_defaults_on_container_expiration_policies.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class SetRegexDefaultsOnContainerExpirationPolicies < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + change_column_default :container_expiration_policies, :name_regex, '.*' + change_column_default :container_expiration_policies, :enabled, false + end + end + + def down + with_lock_retries do + change_column_default :container_expiration_policies, :name_regex, nil + change_column_default :container_expiration_policies, :enabled, true + end + end +end diff --git a/db/migrate/20201008224441_add_position_into_security_findings.rb b/db/migrate/20201008224441_add_position_into_security_findings.rb new file mode 100644 index 00000000000..ee6d5370f83 --- /dev/null +++ b/db/migrate/20201008224441_add_position_into_security_findings.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddPositionIntoSecurityFindings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :security_findings, :position, :integer + end + end + + def down + with_lock_retries do + remove_column :security_findings, :position + end + end +end diff --git a/db/migrate/20201012073022_remove_not_null_constraint_on_framework.rb b/db/migrate/20201012073022_remove_not_null_constraint_on_framework.rb new file mode 100644 index 00000000000..b8cc8984575 --- /dev/null +++ b/db/migrate/20201012073022_remove_not_null_constraint_on_framework.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class RemoveNotNullConstraintOnFramework < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + GDPR_FRAMEWORK_ID = 1 + + disable_ddl_transaction! + + class TmpComplianceProjectFrameworkSetting < ActiveRecord::Base + self.table_name = 'project_compliance_framework_settings' + self.primary_key = :project_id + + include EachBatch + end + + def up + change_column_null :project_compliance_framework_settings, :framework, true + end + + def down + # Custom frameworks cannot be rolled back easily since we don't have enum for them. + # To make the database consistent, we mark them as GDPR framework. + # Note: framework customization will be implemented in the next 1-3 releases so data + # corruption due to the rollback is unlikely. + TmpComplianceProjectFrameworkSetting.each_batch(of: 100) do |query| + query.where(framework: nil).update_all(framework: GDPR_FRAMEWORK_ID) + end + + change_column_null :project_compliance_framework_settings, :framework, false + end +end diff --git a/db/migrate/20201012122428_add_container_registry_expiration_policies_worker_capacity_constraint.rb b/db/migrate/20201012122428_add_container_registry_expiration_policies_worker_capacity_constraint.rb new file mode 100644 index 00000000000..e4f7d1309a3 --- /dev/null +++ b/db/migrate/20201012122428_add_container_registry_expiration_policies_worker_capacity_constraint.rb @@ -0,0 +1,22 @@ +# 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 AddContainerRegistryExpirationPoliciesWorkerCapacityConstraint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + CONSTRAINT_NAME = 'app_settings_registry_exp_policies_worker_capacity_positive' + + disable_ddl_transaction! + + def up + add_check_constraint :application_settings, 'container_registry_expiration_policies_worker_capacity >= 0', CONSTRAINT_NAME + end + + def down + remove_check_constraint :application_settings, CONSTRAINT_NAME + end +end diff --git a/db/migrate/20201012134230_create_ci_test_cases.rb b/db/migrate/20201012134230_create_ci_test_cases.rb new file mode 100644 index 00000000000..fd1bcaf1093 --- /dev/null +++ b/db/migrate/20201012134230_create_ci_test_cases.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CreateCiTestCases < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless table_exists?(:ci_test_cases) + create_table :ci_test_cases do |t| + t.bigint :project_id, null: false + t.text :key_hash, null: false + + t.index [:project_id, :key_hash], unique: true + # NOTE: FK for projects will be added on a separate migration as per guidelines + end + end + + add_text_limit :ci_test_cases, :key_hash, 64 + end + + def down + drop_table :ci_test_cases + end +end diff --git a/db/migrate/20201012135330_create_ci_test_case_failures.rb b/db/migrate/20201012135330_create_ci_test_case_failures.rb new file mode 100644 index 00000000000..7eaf7b5256d --- /dev/null +++ b/db/migrate/20201012135330_create_ci_test_case_failures.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class CreateCiTestCaseFailures < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + create_table :ci_test_case_failures do |t| + t.datetime_with_timezone :failed_at + t.bigint :test_case_id, null: false + t.bigint :build_id, null: false + + t.index [:test_case_id, :failed_at, :build_id], name: 'index_test_case_failures_unique_columns', unique: true, order: { failed_at: :desc } + t.index :build_id + t.foreign_key :ci_test_cases, column: :test_case_id, on_delete: :cascade + # NOTE: FK for ci_builds will be added on a separate migration as per guidelines + end + end + + def down + drop_table :ci_test_case_failures + end +end diff --git a/db/migrate/20201012140110_add_projects_fk_to_ci_test_cases.rb b/db/migrate/20201012140110_add_projects_fk_to_ci_test_cases.rb new file mode 100644 index 00000000000..d30b332e41a --- /dev/null +++ b/db/migrate/20201012140110_add_projects_fk_to_ci_test_cases.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddProjectsFkToCiTestCases < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :ci_test_cases, :projects, column: :project_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :ci_test_cases, column: :project_id + end + end +end diff --git a/db/migrate/20201012140452_add_ci_builds_fk_to_ci_test_case_failures.rb b/db/migrate/20201012140452_add_ci_builds_fk_to_ci_test_case_failures.rb new file mode 100644 index 00000000000..0f2fdf071fa --- /dev/null +++ b/db/migrate/20201012140452_add_ci_builds_fk_to_ci_test_case_failures.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddCiBuildsFkToCiTestCaseFailures < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :ci_test_case_failures, :ci_builds, column: :build_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :ci_test_case_failures, column: :build_id + end + end +end diff --git a/db/migrate/20201014163633_specify_primary_key_where_missing.rb b/db/migrate/20201014163633_specify_primary_key_where_missing.rb new file mode 100644 index 00000000000..bca111dacf2 --- /dev/null +++ b/db/migrate/20201014163633_specify_primary_key_where_missing.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +class SpecifyPrimaryKeyWhereMissing < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + TABLES = { + project_authorizations: [:index_project_authorizations_on_user_id_project_id_access_level, %i(user_id project_id access_level)], + analytics_language_trend_repository_languages: [:analytics_repository_languages_unique_index, %i(programming_language_id project_id snapshot_date)], + approval_project_rules_protected_branches: [:index_approval_project_rules_protected_branches_unique, %i(approval_project_rule_id protected_branch_id)], + ci_build_trace_sections: [:index_ci_build_trace_sections_on_build_id_and_section_name_id, %i(build_id section_name_id)], + deployment_merge_requests: [:idx_deployment_merge_requests_unique_index, %i(deployment_id merge_request_id)], + issue_assignees: [:index_issue_assignees_on_issue_id_and_user_id, %i(issue_id user_id)], + issues_prometheus_alert_events: [:issue_id_prometheus_alert_event_id_index, %i(issue_id prometheus_alert_event_id)], + issues_self_managed_prometheus_alert_events: [:issue_id_self_managed_prometheus_alert_event_id_index, %i(issue_id self_managed_prometheus_alert_event_id)], + merge_request_diff_commits: [:index_merge_request_diff_commits_on_mr_diff_id_and_order, %i(merge_request_diff_id relative_order)], + merge_request_diff_files: [:index_merge_request_diff_files_on_mr_diff_id_and_order, %i(merge_request_diff_id relative_order)], + milestone_releases: [:index_miletone_releases_on_milestone_and_release, %i(milestone_id release_id)], + project_pages_metadata: [:index_project_pages_metadata_on_project_id, %i(project_id)], + push_event_payloads: [:index_push_event_payloads_on_event_id, %i(event_id)], + repository_languages: [:index_repository_languages_on_project_and_languages_id, %i(project_id programming_language_id)], + user_interacted_projects: [:index_user_interacted_projects_on_project_id_and_user_id, %i(project_id user_id)], + users_security_dashboard_projects: [:users_security_dashboard_projects_unique_index, %i(project_id user_id)] + }.freeze + + def up + TABLES.each do |table, (unique_index, _)| + with_lock_retries do + execute "ALTER TABLE #{table} ADD CONSTRAINT #{table}_pkey PRIMARY KEY USING INDEX #{unique_index}" if index_exists_by_name?(table, unique_index) + end + end + end + + def down + TABLES.each do |table, (unique_index, columns)| + add_concurrent_index table, columns, name: unique_index, unique: true + + with_lock_retries do + execute "ALTER TABLE #{table} DROP CONSTRAINT #{table}_pkey" + end + end + end +end diff --git a/db/migrate/20201015121805_add_project_foreign_key_to_csv_issue_imports.rb b/db/migrate/20201015121805_add_project_foreign_key_to_csv_issue_imports.rb new file mode 100644 index 00000000000..9476d2d55bd --- /dev/null +++ b/db/migrate/20201015121805_add_project_foreign_key_to_csv_issue_imports.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddProjectForeignKeyToCsvIssueImports < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :csv_issue_imports, :projects, column: :project_id + end + + def down + with_lock_retries do + remove_foreign_key :csv_issue_imports, column: :project_id + end + end +end diff --git a/db/migrate/20201015121825_add_user_foreign_key_to_csv_issue_imports.rb b/db/migrate/20201015121825_add_user_foreign_key_to_csv_issue_imports.rb new file mode 100644 index 00000000000..ae91695bff4 --- /dev/null +++ b/db/migrate/20201015121825_add_user_foreign_key_to_csv_issue_imports.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddUserForeignKeyToCsvIssueImports < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :csv_issue_imports, :users, column: :user_id + end + + def down + with_lock_retries do + remove_foreign_key :csv_issue_imports, column: :user_id + end + end +end diff --git a/db/migrate/20201015194852_add_index_on_state_for_dast_site_validations.rb b/db/migrate/20201015194852_add_index_on_state_for_dast_site_validations.rb new file mode 100644 index 00000000000..785d7c8829c --- /dev/null +++ b/db/migrate/20201015194852_add_index_on_state_for_dast_site_validations.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddIndexOnStateForDastSiteValidations < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + OLD_INDEX_NAME = 'index_dast_site_validations_on_url_base' + NEW_INDEX_NAME = 'index_dast_site_validations_on_url_base_and_state' + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :dast_site_validations, [:url_base, :state], name: NEW_INDEX_NAME + remove_concurrent_index_by_name :dast_site_validations, OLD_INDEX_NAME + end + + def down + add_concurrent_index :dast_site_validations, :url_base, name: OLD_INDEX_NAME + remove_concurrent_index_by_name :dast_site_validations, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20201015231049_add_ci_build_id_to_terraform_state_versions.rb b/db/migrate/20201015231049_add_ci_build_id_to_terraform_state_versions.rb new file mode 100644 index 00000000000..539b2af5fc4 --- /dev/null +++ b/db/migrate/20201015231049_add_ci_build_id_to_terraform_state_versions.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class AddCiBuildIdToTerraformStateVersions < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_terraform_state_versions_on_ci_build_id' + + disable_ddl_transaction! + + def up + unless column_exists?(:terraform_state_versions, :ci_build_id) + add_column :terraform_state_versions, :ci_build_id, :bigint + end + + add_concurrent_index :terraform_state_versions, :ci_build_id, name: INDEX_NAME + add_concurrent_foreign_key :terraform_state_versions, :ci_builds, column: :ci_build_id, on_delete: :nullify + end + + def down + with_lock_retries do + remove_foreign_key_if_exists :terraform_state_versions, :ci_builds, column: :ci_build_id + end + + remove_concurrent_index_by_name :terraform_state_versions, INDEX_NAME + remove_column :terraform_state_versions, :ci_build_id + end +end diff --git a/db/migrate/20201016074302_add_index_project_id_and_id_to_container_repositories.rb b/db/migrate/20201016074302_add_index_project_id_and_id_to_container_repositories.rb new file mode 100644 index 00000000000..b2e7c62ba0c --- /dev/null +++ b/db/migrate/20201016074302_add_index_project_id_and_id_to_container_repositories.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexProjectIdAndIdToContainerRepositories < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_container_repositories_on_project_id_and_id' + + disable_ddl_transaction! + + def up + add_concurrent_index(:container_repositories, [:project_id, :id], name: INDEX_NAME) + end + + def down + remove_concurrent_index(:container_repositories, [:project_id, :id], name: INDEX_NAME) + end +end diff --git a/db/migrate/20201019091307_add_unique_index_on_scan_id_and_position_of_security_findings.rb b/db/migrate/20201019091307_add_unique_index_on_scan_id_and_position_of_security_findings.rb new file mode 100644 index 00000000000..3303e41d8a1 --- /dev/null +++ b/db/migrate/20201019091307_add_unique_index_on_scan_id_and_position_of_security_findings.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddUniqueIndexOnScanIdAndPositionOfSecurityFindings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_security_findings_on_scan_id_and_position' + + disable_ddl_transaction! + + def up + add_concurrent_index :security_findings, [:scan_id, :position], unique: true, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :security_findings, INDEX_NAME + end +end diff --git a/db/migrate/20201019101549_add_es_custom_analyzers_settings.rb b/db/migrate/20201019101549_add_es_custom_analyzers_settings.rb new file mode 100644 index 00000000000..47fd9ebbb8e --- /dev/null +++ b/db/migrate/20201019101549_add_es_custom_analyzers_settings.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AddEsCustomAnalyzersSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :elasticsearch_analyzers_smartcn_enabled, :bool, null: false, default: false + add_column :application_settings, :elasticsearch_analyzers_smartcn_search, :bool, null: false, default: false + add_column :application_settings, :elasticsearch_analyzers_kuromoji_enabled, :bool, null: false, default: false + add_column :application_settings, :elasticsearch_analyzers_kuromoji_search, :bool, null: false, default: false + end +end diff --git a/db/migrate/20201019111952_add_sha256_and_filecount_to_pages_deployments.rb b/db/migrate/20201019111952_add_sha256_and_filecount_to_pages_deployments.rb new file mode 100644 index 00000000000..1921701626d --- /dev/null +++ b/db/migrate/20201019111952_add_sha256_and_filecount_to_pages_deployments.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class AddSha256AndFilecountToPagesDeployments < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + # pages_deployments were never enabled on any production/staging + # environments, so we safely delete them for people who enabled + # them locally + execute "DELETE FROM pages_deployments" + + # rubocop:disable Rails/NotNullColumn + add_column :pages_deployments, :file_count, :integer, null: false + add_column :pages_deployments, :file_sha256, :binary, null: false + # rubocop:enable Rails/NotNullColumn + end + + def down + remove_column :pages_deployments, :file_sha256 + remove_column :pages_deployments, :file_count + end +end diff --git a/db/migrate/20201019113009_add_new_user_signups_cap_to_application_settings.rb b/db/migrate/20201019113009_add_new_user_signups_cap_to_application_settings.rb new file mode 100644 index 00000000000..8754b0d481e --- /dev/null +++ b/db/migrate/20201019113009_add_new_user_signups_cap_to_application_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddNewUserSignupsCapToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :application_settings, :new_user_signups_cap, :integer + end +end diff --git a/db/migrate/20201019130244_remove_license_compliance_temp_index.rb b/db/migrate/20201019130244_remove_license_compliance_temp_index.rb new file mode 100644 index 00000000000..d0383d999ed --- /dev/null +++ b/db/migrate/20201019130244_remove_license_compliance_temp_index.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RemoveLicenseComplianceTempIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_ci_job_artifacts_on_license_compliance_file_types' + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :ci_job_artifacts, name: INDEX_NAME + end + + def down + add_concurrent_index :ci_job_artifacts, [:job_id, :file_type], where: 'file_type = 10 OR file_type = 101', name: INDEX_NAME + end +end diff --git a/db/migrate/20201019152046_add_default_branch_to_daily_build_group_report_result.rb b/db/migrate/20201019152046_add_default_branch_to_daily_build_group_report_result.rb new file mode 100644 index 00000000000..8a0051b8106 --- /dev/null +++ b/db/migrate/20201019152046_add_default_branch_to_daily_build_group_report_result.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddDefaultBranchToDailyBuildGroupReportResult < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column :ci_daily_build_group_report_results, :default_branch, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20201019161924_add_partitioned_table_view.rb b/db/migrate/20201019161924_add_partitioned_table_view.rb new file mode 100644 index 00000000000..45bbfda40ff --- /dev/null +++ b/db/migrate/20201019161924_add_partitioned_table_view.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class AddPartitionedTableView < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + execute(<<~SQL) + CREATE OR REPLACE VIEW postgres_partitioned_tables AS + SELECT + pg_namespace.nspname::text || '.'::text || pg_class.relname::text AS identifier, + pg_class.oid AS oid, + pg_namespace.nspname AS schema, + pg_class.relname AS name, + CASE partitioned_tables.partstrat + WHEN 'l' THEN 'list' + WHEN 'r' THEN 'range' + WHEN 'h' THEN 'hash' + END as strategy, + array_agg(pg_attribute.attname) as key_columns + FROM ( + SELECT + partrelid, + partstrat, + unnest(partattrs) as column_position + FROM pg_partitioned_table + ) partitioned_tables + INNER JOIN pg_class + ON partitioned_tables.partrelid = pg_class.oid + INNER JOIN pg_namespace + ON pg_class.relnamespace = pg_namespace.oid + INNER JOIN pg_attribute + ON pg_attribute.attrelid = pg_class.oid + AND pg_attribute.attnum = partitioned_tables.column_position + WHERE pg_namespace.nspname = current_schema() + GROUP BY identifier, pg_class.oid, schema, name, strategy; + SQL + end + + def down + execute(<<~SQL) + DROP VIEW IF EXISTS postgres_partitioned_tables + SQL + end +end diff --git a/db/migrate/20201019172704_add_partitions_view.rb b/db/migrate/20201019172704_add_partitions_view.rb new file mode 100644 index 00000000000..991d137faf3 --- /dev/null +++ b/db/migrate/20201019172704_add_partitions_view.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class AddPartitionsView < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + execute(<<~SQL) + CREATE OR REPLACE VIEW postgres_partitions AS + SELECT + pg_namespace.nspname::text || '.'::text || pg_class.relname::text AS identifier, + pg_class.oid AS oid, + pg_namespace.nspname AS schema, + pg_class.relname AS name, + parent_namespace.nspname::text || '.'::text || parent_class.relname::text AS parent_identifier, + pg_get_expr(pg_class.relpartbound, pg_inherits.inhrelid) AS condition + FROM pg_class + INNER JOIN pg_namespace + ON pg_namespace.oid = pg_class.relnamespace + INNER JOIN pg_inherits + ON pg_class.oid = pg_inherits.inhrelid + INNER JOIN pg_class parent_class + ON pg_inherits.inhparent = parent_class.oid + INNER JOIN pg_namespace parent_namespace + ON parent_class.relnamespace = parent_namespace.oid + WHERE pg_class.relispartition + AND pg_namespace.nspname IN ( + current_schema(), + 'gitlab_partitions_dynamic', + 'gitlab_partitions_static' + ) + SQL + end + + def down + execute(<<~SQL) + DROP VIEW IF EXISTS postgres_partitions + SQL + end +end diff --git a/db/migrate/20201021085007_create_analytics_devops_adoption_segments.rb b/db/migrate/20201021085007_create_analytics_devops_adoption_segments.rb new file mode 100644 index 00000000000..3e322675ba6 --- /dev/null +++ b/db/migrate/20201021085007_create_analytics_devops_adoption_segments.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class CreateAnalyticsDevopsAdoptionSegments < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table :analytics_devops_adoption_segments, if_not_exists: true do |t| + t.text :name, null: false, index: { unique: true } + t.datetime_with_timezone :last_recorded_at + + t.timestamps_with_timezone + end + + add_text_limit :analytics_devops_adoption_segments, :name, 255 + end + + def down + drop_table :analytics_devops_adoption_segments + end +end diff --git a/db/migrate/20201021101956_add_index_route_on_name_trigram_to_route.rb b/db/migrate/20201021101956_add_index_route_on_name_trigram_to_route.rb new file mode 100644 index 00000000000..cf65c7500c5 --- /dev/null +++ b/db/migrate/20201021101956_add_index_route_on_name_trigram_to_route.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexRouteOnNameTrigramToRoute < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_route_on_name_trigram' + + disable_ddl_transaction! + + def up + add_concurrent_index :routes, :name, name: INDEX_NAME, using: :gin, opclass: { name: :gin_trgm_ops } + end + + def down + remove_concurrent_index_by_name(:routes, INDEX_NAME) + end +end diff --git a/db/migrate/20201021102554_create_analytics_devops_adoption_segment_selections.rb b/db/migrate/20201021102554_create_analytics_devops_adoption_segment_selections.rb new file mode 100644 index 00000000000..c5aac7a82a5 --- /dev/null +++ b/db/migrate/20201021102554_create_analytics_devops_adoption_segment_selections.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CreateAnalyticsDevopsAdoptionSegmentSelections < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + create_table :analytics_devops_adoption_segment_selections do |t| + t.references :segment, index: { name: 'index_on_segment_selections_segment_id' }, null: false, foreign_key: { to_table: :analytics_devops_adoption_segments, on_delete: :cascade } + t.bigint :group_id + t.bigint :project_id + t.index [:group_id, :segment_id], unique: true, name: 'index_on_segment_selections_group_id_segment_id' + t.index [:project_id, :segment_id], unique: true, name: 'index_on_segment_selections_project_id_segment_id' + + t.timestamps_with_timezone + end + end +end diff --git a/db/migrate/20201021105347_add_foreign_key_project_id_to_segment_selection.rb b/db/migrate/20201021105347_add_foreign_key_project_id_to_segment_selection.rb new file mode 100644 index 00000000000..651770e059c --- /dev/null +++ b/db/migrate/20201021105347_add_foreign_key_project_id_to_segment_selection.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddForeignKeyProjectIdToSegmentSelection < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key(:analytics_devops_adoption_segment_selections, :projects, column: :project_id, on_delete: :cascade) + end + + def down + with_lock_retries do + remove_foreign_key :analytics_devops_adoption_segment_selections, column: :project_id + end + end +end diff --git a/db/migrate/20201021105600_add_foreign_key_group_id_to_segment_selection.rb b/db/migrate/20201021105600_add_foreign_key_group_id_to_segment_selection.rb new file mode 100644 index 00000000000..3ee73ee3a64 --- /dev/null +++ b/db/migrate/20201021105600_add_foreign_key_group_id_to_segment_selection.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddForeignKeyGroupIdToSegmentSelection < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_foreign_key(:analytics_devops_adoption_segment_selections, :namespaces, column: :group_id, on_delete: :cascade) + end + + def down + with_lock_retries do + remove_foreign_key :analytics_devops_adoption_segment_selections, column: :group_id + end + end +end diff --git a/db/migrate/20201021105959_add_check_constraint_to_segment_selection.rb b/db/migrate/20201021105959_add_check_constraint_to_segment_selection.rb new file mode 100644 index 00000000000..68fec36aa8a --- /dev/null +++ b/db/migrate/20201021105959_add_check_constraint_to_segment_selection.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddCheckConstraintToSegmentSelection < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + CONSTRAINT_NAME = 'segment_selection_project_id_or_group_id_required' + + def up + add_check_constraint :analytics_devops_adoption_segment_selections, '(project_id != NULL AND group_id IS NULL) OR (group_id != NULL AND project_id IS NULL)', CONSTRAINT_NAME + end + + def down + remove_check_constraint :analytics_devops_adoption_segment_selections, CONSTRAINT_NAME + end +end diff --git a/db/migrate/20201021142812_add_index_to_ci_daily_build_group_report_results.rb b/db/migrate/20201021142812_add_index_to_ci_daily_build_group_report_results.rb new file mode 100644 index 00000000000..c811e3deeda --- /dev/null +++ b/db/migrate/20201021142812_add_index_to_ci_daily_build_group_report_results.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddIndexToCiDailyBuildGroupReportResults < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_ci_daily_build_group_report_results_on_project_and_date' + + disable_ddl_transaction! + + def up + add_concurrent_index( + :ci_daily_build_group_report_results, + [:project_id, :date], + order: { date: :desc }, + where: "default_branch = TRUE AND (data -> 'coverage') IS NOT NULL", + name: INDEX_NAME + ) + end + + def down + remove_concurrent_index_by_name(:ci_daily_build_group_report_results, INDEX_NAME) + end +end diff --git a/db/migrate/20201021152210_add_secret_detection_token_revocation_application_settings.rb b/db/migrate/20201021152210_add_secret_detection_token_revocation_application_settings.rb new file mode 100644 index 00000000000..6334dcd8c1a --- /dev/null +++ b/db/migrate/20201021152210_add_secret_detection_token_revocation_application_settings.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddSecretDetectionTokenRevocationApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + add_column :application_settings, :secret_detection_token_revocation_enabled, :boolean, default: false, null: false + add_column :application_settings, :secret_detection_token_revocation_url, :text, null: true # rubocop:disable Migration/AddLimitToTextColumns + + add_column :application_settings, :encrypted_secret_detection_token_revocation_token, :text + add_column :application_settings, :encrypted_secret_detection_token_revocation_token_iv, :text + end + + def down + remove_column :application_settings, :secret_detection_token_revocation_enabled + remove_column :application_settings, :secret_detection_token_revocation_url + + remove_column :application_settings, :encrypted_secret_detection_token_revocation_token + remove_column :application_settings, :encrypted_secret_detection_token_revocation_token_iv + end +end diff --git a/db/migrate/20201021190539_add_text_limit_to_secret_detection_token_revocation_application_settings.rb b/db/migrate/20201021190539_add_text_limit_to_secret_detection_token_revocation_application_settings.rb new file mode 100644 index 00000000000..ea5e12322d0 --- /dev/null +++ b/db/migrate/20201021190539_add_text_limit_to_secret_detection_token_revocation_application_settings.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTextLimitToSecretDetectionTokenRevocationApplicationSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :secret_detection_token_revocation_url, 255 + end + + def down + remove_text_limit :application_settings, :secret_detection_token_revocation_url + end +end diff --git a/db/migrate/20201021220101_add_merge_trains_enabled.rb b/db/migrate/20201021220101_add_merge_trains_enabled.rb new file mode 100644 index 00000000000..88a71897435 --- /dev/null +++ b/db/migrate/20201021220101_add_merge_trains_enabled.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddMergeTrainsEnabled < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: false + end +end diff --git a/db/migrate/20201022080802_add_repository_read_only_to_snippets.rb b/db/migrate/20201022080802_add_repository_read_only_to_snippets.rb new file mode 100644 index 00000000000..d0cb329fb02 --- /dev/null +++ b/db/migrate/20201022080802_add_repository_read_only_to_snippets.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddRepositoryReadOnlyToSnippets < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :snippets, :repository_read_only, :boolean, default: false, null: false + end +end diff --git a/db/migrate/20201022094845_add_historical_data_recorded_at.rb b/db/migrate/20201022094845_add_historical_data_recorded_at.rb new file mode 100644 index 00000000000..c90889e2d38 --- /dev/null +++ b/db/migrate/20201022094845_add_historical_data_recorded_at.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddHistoricalDataRecordedAt < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + add_column(:historical_data, :recorded_at, :timestamptz) + end + + def down + remove_column(:historical_data, :recorded_at) + end +end diff --git a/db/migrate/20201022094846_update_historical_data_recorded_at.rb b/db/migrate/20201022094846_update_historical_data_recorded_at.rb new file mode 100644 index 00000000000..bd1889149bb --- /dev/null +++ b/db/migrate/20201022094846_update_historical_data_recorded_at.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class UpdateHistoricalDataRecordedAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + update_value = Arel.sql("COALESCE(created_at, date + '12:00'::time AT TIME ZONE '#{Time.zone&.tzinfo&.name || "Etc/UTC"}')") + + update_column_in_batches(:historical_data, :recorded_at, update_value) do |table, query| + query.where(table[:recorded_at].eq(nil)) + end + + add_not_null_constraint :historical_data, :recorded_at + + change_column_null :historical_data, :date, true + end + + def down + change_column_null :historical_data, :date, false + + remove_not_null_constraint :historical_data, :recorded_at + + update_column_in_batches(:historical_data, :recorded_at, nil) do |table, query| + query.where(table[:recorded_at].not_eq(nil)) + end + end +end diff --git a/db/migrate/20201022103304_add_availability_to_user_statuses.rb b/db/migrate/20201022103304_add_availability_to_user_statuses.rb new file mode 100644 index 00000000000..9144c81fcfb --- /dev/null +++ b/db/migrate/20201022103304_add_availability_to_user_statuses.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddAvailabilityToUserStatuses < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :user_statuses, :availability, :integer, limit: 2, default: 0, null: false + end +end diff --git a/db/migrate/20201022144501_create_snippet_repository_storage_move.rb b/db/migrate/20201022144501_create_snippet_repository_storage_move.rb new file mode 100644 index 00000000000..7db38191942 --- /dev/null +++ b/db/migrate/20201022144501_create_snippet_repository_storage_move.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class CreateSnippetRepositoryStorageMove < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless table_exists?(:snippet_repository_storage_moves) + with_lock_retries do + create_table :snippet_repository_storage_moves do |t| + t.timestamps_with_timezone + t.references :snippet, index: true, null: false, foreign_key: { on_delete: :cascade } + t.integer :state, limit: 2, default: 1, null: false + t.text :source_storage_name, null: false + t.text :destination_storage_name, null: false + end + end + end + + add_text_limit(:snippet_repository_storage_moves, :source_storage_name, 255, constraint_name: 'snippet_repository_storage_moves_source_storage_name') + add_text_limit(:snippet_repository_storage_moves, :destination_storage_name, 255, constraint_name: 'snippet_repository_storage_moves_destination_storage_name') + end + + def down + with_lock_retries do + drop_table :snippet_repository_storage_moves + end + end +end diff --git a/db/migrate/20201022191817_add_has_vulnerabilities_into_project_settings.rb b/db/migrate/20201022191817_add_has_vulnerabilities_into_project_settings.rb new file mode 100644 index 00000000000..bb2d683c4e2 --- /dev/null +++ b/db/migrate/20201022191817_add_has_vulnerabilities_into_project_settings.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddHasVulnerabilitiesIntoProjectSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :project_settings, :has_vulnerabilities, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :project_settings, :has_vulnerabilities + end + end +end diff --git a/db/migrate/20201022192254_index_project_settings_on_project_id_partially.rb b/db/migrate/20201022192254_index_project_settings_on_project_id_partially.rb new file mode 100644 index 00000000000..57247bd0f22 --- /dev/null +++ b/db/migrate/20201022192254_index_project_settings_on_project_id_partially.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class IndexProjectSettingsOnProjectIdPartially < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_project_settings_on_project_id_partially' + + disable_ddl_transaction! + + def up + add_concurrent_index :project_settings, :project_id, name: INDEX_NAME, where: 'has_vulnerabilities IS TRUE' + end + + def down + remove_concurrent_index_by_name :project_settings, INDEX_NAME + end +end diff --git a/db/migrate/20201023114628_create_merge_request_cleanup_schedules.rb b/db/migrate/20201023114628_create_merge_request_cleanup_schedules.rb new file mode 100644 index 00000000000..f63738682b1 --- /dev/null +++ b/db/migrate/20201023114628_create_merge_request_cleanup_schedules.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class CreateMergeRequestCleanupSchedules < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + create_table :merge_request_cleanup_schedules, id: false do |t| + t.references :merge_request, primary_key: true, index: { unique: true }, null: false, foreign_key: { on_delete: :cascade } + t.datetime_with_timezone :scheduled_at, null: false + t.datetime_with_timezone :completed_at, null: true + + t.timestamps_with_timezone + + t.index :scheduled_at, where: 'completed_at IS NULL', name: 'index_mr_cleanup_schedules_timestamps' + end + end + end + + def down + with_lock_retries do + drop_table :merge_request_cleanup_schedules + end + end +end diff --git a/db/migrate/20201026200736_seed_merge_trains_enabled.rb b/db/migrate/20201026200736_seed_merge_trains_enabled.rb new file mode 100644 index 00000000000..c22c2a408bc --- /dev/null +++ b/db/migrate/20201026200736_seed_merge_trains_enabled.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class SeedMergeTrainsEnabled < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + update_column_in_batches(:project_ci_cd_settings, :merge_trains_enabled, true) do |table, query| + query.where(table[:merge_pipelines_enabled].eq(true)) + end + end + + def down + # no-op + end +end diff --git a/db/migrate/20201027002551_migrate_services_to_http_integrations.rb b/db/migrate/20201027002551_migrate_services_to_http_integrations.rb new file mode 100644 index 00000000000..5fe05320862 --- /dev/null +++ b/db/migrate/20201027002551_migrate_services_to_http_integrations.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class MigrateServicesToHttpIntegrations < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + ALERT_SERVICE_TYPE = 'AlertsService' + SERVICE_NAMES_IDENTIFIER = { + name: 'HTTP endpoint', + identifier: 'legacy' + } + + class HttpIntegration < ActiveRecord::Base + self.table_name = 'alert_management_http_integrations' + end + + # For each Alerts service, + # Create the matching HttpIntegration + def up + HttpIntegration.reset_column_information + + sql = <<~SQL + SELECT * FROM services + JOIN alerts_service_data + ON (services.id = alerts_service_data.service_id) + WHERE type = '#{ALERT_SERVICE_TYPE}' + AND active = TRUE + SQL + + current_time = Time.current + + values = select_all(sql).map do |alerts_service| + { + project_id: alerts_service['project_id'], + name: SERVICE_NAMES_IDENTIFIER[:name], + endpoint_identifier: SERVICE_NAMES_IDENTIFIER[:identifier], + encrypted_token: alerts_service['encrypted_token'], + encrypted_token_iv: alerts_service['encrypted_token_iv'], + active: alerts_service['active'], + updated_at: current_time, + created_at: current_time + } + end + + HttpIntegration.insert_all(values) if values.present? + end + + def down + # no-op + end +end diff --git a/db/migrate/20201027135651_add_auto_rollback_setting.rb b/db/migrate/20201027135651_add_auto_rollback_setting.rb new file mode 100644 index 00000000000..8e916ac9d36 --- /dev/null +++ b/db/migrate/20201027135651_add_auto_rollback_setting.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddAutoRollbackSetting < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + add_column :project_ci_cd_settings, :auto_rollback_enabled, :boolean, default: false, null: false + end + end + + def down + with_lock_retries do + remove_column :project_ci_cd_settings, :auto_rollback_enabled + end + end +end diff --git a/db/migrate/20201027210127_add_index_to_oauth_access_grants_resource_owner_id.rb b/db/migrate/20201027210127_add_index_to_oauth_access_grants_resource_owner_id.rb new file mode 100644 index 00000000000..035d2fb4386 --- /dev/null +++ b/db/migrate/20201027210127_add_index_to_oauth_access_grants_resource_owner_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexToOauthAccessGrantsResourceOwnerId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_oauth_access_grants_on_resource_owner_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :oauth_access_grants, %i[resource_owner_id application_id created_at], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :oauth_access_grants, INDEX_NAME + end +end diff --git a/db/migrate/20201027211138_increase_default_diff_max_patch_bytes.rb b/db/migrate/20201027211138_increase_default_diff_max_patch_bytes.rb new file mode 100644 index 00000000000..92d9025706f --- /dev/null +++ b/db/migrate/20201027211138_increase_default_diff_max_patch_bytes.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class IncreaseDefaultDiffMaxPatchBytes < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + change_column_default(:application_settings, :diff_max_patch_bytes, from: 102400, to: 204800) + end +end diff --git a/db/migrate/20201028160831_add_temporary_index_to_vulnerabilities_table.rb b/db/migrate/20201028160831_add_temporary_index_to_vulnerabilities_table.rb new file mode 100644 index 00000000000..05bb75be75a --- /dev/null +++ b/db/migrate/20201028160831_add_temporary_index_to_vulnerabilities_table.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddTemporaryIndexToVulnerabilitiesTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'temporary_index_vulnerabilities_on_id' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerabilities, :id, where: "state = 2 AND (dismissed_at IS NULL OR dismissed_by_id IS NULL)", name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerabilities, INDEX_NAME + end +end diff --git a/db/migrate/20201028184640_add_helm_major_version_to_clusters.rb b/db/migrate/20201028184640_add_helm_major_version_to_clusters.rb new file mode 100644 index 00000000000..2169fd41826 --- /dev/null +++ b/db/migrate/20201028184640_add_helm_major_version_to_clusters.rb @@ -0,0 +1,12 @@ +# 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 AddHelmMajorVersionToClusters < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column(:clusters, :helm_major_version, :integer, default: 2, null: false) + end +end diff --git a/db/migrate/20201028204306_migrate_default_diff_max_patch_bytes_to_minimum_200kb.rb b/db/migrate/20201028204306_migrate_default_diff_max_patch_bytes_to_minimum_200kb.rb new file mode 100644 index 00000000000..11d47904e67 --- /dev/null +++ b/db/migrate/20201028204306_migrate_default_diff_max_patch_bytes_to_minimum_200kb.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class MigrateDefaultDiffMaxPatchBytesToMinimum200kb < ActiveRecord::Migration[6.0] + DOWNTIME = false + MAX_SIZE = 200.kilobytes + + class ApplicationSetting < ActiveRecord::Base + self.table_name = 'application_settings' + end + + def up + table = ApplicationSetting.arel_table + ApplicationSetting.where(table[:diff_max_patch_bytes].lt(MAX_SIZE)).update_all(diff_max_patch_bytes: MAX_SIZE) + end + + def down + table = ApplicationSetting.arel_table + ApplicationSetting.where(table[:diff_max_patch_bytes].eq(MAX_SIZE)).update_all(diff_max_patch_bytes: 100.kilobytes) + end +end diff --git a/db/migrate/20201029143650_rename_application_settings_to_allow_deny_names.rb b/db/migrate/20201029143650_rename_application_settings_to_allow_deny_names.rb new file mode 100644 index 00000000000..2d96da91069 --- /dev/null +++ b/db/migrate/20201029143650_rename_application_settings_to_allow_deny_names.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RenameApplicationSettingsToAllowDenyNames < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + rename_column_concurrently :application_settings, :domain_blacklist_enabled, :domain_denylist_enabled + rename_column_concurrently :application_settings, :domain_blacklist, :domain_denylist + rename_column_concurrently :application_settings, :domain_whitelist, :domain_allowlist + end + + def down + undo_rename_column_concurrently :application_settings, :domain_blacklist_enabled, :domain_denylist_enabled + undo_rename_column_concurrently :application_settings, :domain_blacklist, :domain_denylist + undo_rename_column_concurrently :application_settings, :domain_whitelist, :domain_allowlist + end +end diff --git a/db/migrate/20201029144444_create_vulnerability_finding_links.rb b/db/migrate/20201029144444_create_vulnerability_finding_links.rb new file mode 100644 index 00000000000..80f93b9a0af --- /dev/null +++ b/db/migrate/20201029144444_create_vulnerability_finding_links.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class CreateVulnerabilityFindingLinks < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + create_table :vulnerability_finding_links, if_not_exists: true do |t| + t.timestamps_with_timezone null: false + t.references :vulnerability_occurrence, index: { name: 'finding_links_on_vulnerability_occurrence_id' }, null: false, foreign_key: { on_delete: :cascade } + t.text :name, limit: 255 + t.text :url, limit: 2048, null: false + end + + add_text_limit :vulnerability_finding_links, :name, 255 + add_text_limit :vulnerability_finding_links, :url, 2048 + end + + def down + drop_table :vulnerability_finding_links + end +end diff --git a/db/migrate/20201030092151_add_requirements_access_level_to_project_features.rb b/db/migrate/20201030092151_add_requirements_access_level_to_project_features.rb new file mode 100644 index 00000000000..e4ba7b2adb9 --- /dev/null +++ b/db/migrate/20201030092151_add_requirements_access_level_to_project_features.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddRequirementsAccessLevelToProjectFeatures < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + unless column_exists?(:project_features, :requirements_access_level) + with_lock_retries { add_column :project_features, :requirements_access_level, :integer, default: 20, null: false } + end + end + + def down + if column_exists?(:project_features, :requirements_access_level) + with_lock_retries { remove_column :project_features, :requirements_access_level } + end + end +end diff --git a/db/migrate/20201030200115_add_iid_to_design_management_design.rb b/db/migrate/20201030200115_add_iid_to_design_management_design.rb new file mode 100644 index 00000000000..c31cd86d5e2 --- /dev/null +++ b/db/migrate/20201030200115_add_iid_to_design_management_design.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddIidToDesignManagementDesign < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + add_column :design_management_designs, :iid, :integer + end +end diff --git a/db/migrate/20201030200539_add_index_on_design_management_designs_iid_project_id.rb b/db/migrate/20201030200539_add_index_on_design_management_designs_iid_project_id.rb new file mode 100644 index 00000000000..3ff50c299cb --- /dev/null +++ b/db/migrate/20201030200539_add_index_on_design_management_designs_iid_project_id.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddIndexOnDesignManagementDesignsIidProjectId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEX_NAME = 'index_design_management_designs_on_iid_and_project_id' + + def up + add_concurrent_index :design_management_designs, [:project_id, :iid], + name: INDEX_NAME, + unique: true + end + + def down + remove_concurrent_index_by_name :design_management_designs, INDEX_NAME + end +end diff --git a/db/migrate/20201102184743_add_index_to_incident_issues_on_project_and_created_at.rb b/db/migrate/20201102184743_add_index_to_incident_issues_on_project_and_created_at.rb new file mode 100644 index 00000000000..1fd900002c3 --- /dev/null +++ b/db/migrate/20201102184743_add_index_to_incident_issues_on_project_and_created_at.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class AddIndexToIncidentIssuesOnProjectAndCreatedAt < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + INCIDENT_TYPE = 1 + OLD_INDEX_NAME = 'index_issues_project_id_issue_type_incident' + NEW_INDEX_NAME = 'index_issues_on_project_id_and_created_at_issue_type_incident' + + DOWNTIME = false + disable_ddl_transaction! + + def up + add_concurrent_index :issues, + [:project_id, :created_at], + where: "issue_type = #{INCIDENT_TYPE}", + name: NEW_INDEX_NAME + + remove_concurrent_index_by_name :issues, OLD_INDEX_NAME + end + + def down + add_concurrent_index :issues, + :project_id, + where: "issue_type = #{INCIDENT_TYPE}", + name: OLD_INDEX_NAME + + remove_concurrent_index_by_name :issues, NEW_INDEX_NAME + end +end diff --git a/db/migrate/20201103095752_add_issues_closed_at_index.rb b/db/migrate/20201103095752_add_issues_closed_at_index.rb new file mode 100644 index 00000000000..7a8ee4e8d67 --- /dev/null +++ b/db/migrate/20201103095752_add_issues_closed_at_index.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIssuesClosedAtIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index(:issues, [:project_id, :closed_at]) + end + + def down + remove_concurrent_index_by_name(:issues, 'index_issues_on_project_id_and_closed_at') + end +end diff --git a/db/migrate/20201103171537_add_index_active_billable_users_to_user.rb b/db/migrate/20201103171537_add_index_active_billable_users_to_user.rb new file mode 100644 index 00000000000..3ad7a3f4ca3 --- /dev/null +++ b/db/migrate/20201103171537_add_index_active_billable_users_to_user.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddIndexActiveBillableUsersToUser < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'active_billable_users' + HUMAN_TYPE = 'NULL' + HUMAN_SVC_BOT_TYPES = "#{HUMAN_TYPE}, 6, 4" + BOT_TYPES = '2,6,1,3,7,8' + + disable_ddl_transaction! + + def up + add_concurrent_index :users, :id, name: INDEX_NAME, where: "(state = 'active' AND (user_type is #{HUMAN_TYPE} or user_type in (#{HUMAN_SVC_BOT_TYPES}))) and ((users.user_type IS #{HUMAN_TYPE}) OR (users.user_type <> ALL ('{#{BOT_TYPES}}')))" + end + + def down + remove_concurrent_index_by_name(:users, INDEX_NAME) + end +end diff --git a/db/migrate/20201103184333_create_packages_package_file_build_infos.rb b/db/migrate/20201103184333_create_packages_package_file_build_infos.rb new file mode 100644 index 00000000000..9cb6869cae4 --- /dev/null +++ b/db/migrate/20201103184333_create_packages_package_file_build_infos.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class CreatePackagesPackageFileBuildInfos < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + unless table_exists?(:packages_package_file_build_infos) + with_lock_retries do + create_table :packages_package_file_build_infos do |t| + t.references :package_file, index: true, + null: false, + foreign_key: { to_table: :packages_package_files, on_delete: :cascade }, + type: :bigint + t.references :pipeline, index: true, + null: true, + foreign_key: { to_table: :ci_pipelines, on_delete: :nullify }, + type: :bigint + end + end + end + end + + def down + with_lock_retries do + drop_table :packages_package_file_build_infos + end + end +end diff --git a/db/migrate/20201103202213_update_packages_build_infos_index.rb b/db/migrate/20201103202213_update_packages_build_infos_index.rb new file mode 100644 index 00000000000..d737517045b --- /dev/null +++ b/db/migrate/20201103202213_update_packages_build_infos_index.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class UpdatePackagesBuildInfosIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + NEW_INDEX_NAME = 'idx_packages_build_infos_on_package_id' + OLD_INDEX_NAME = 'index_packages_build_infos_on_package_id' + + def up + add_concurrent_index :packages_build_infos, :package_id, name: NEW_INDEX_NAME + remove_concurrent_index_by_name :packages_build_infos, OLD_INDEX_NAME + end + + def down + # No op. It is possible records would validate the UNIQUE constraint, so it + # cannot be added back to the index. + end +end diff --git a/db/migrate/20201104204739_create_bulk_import_trackers.rb b/db/migrate/20201104204739_create_bulk_import_trackers.rb new file mode 100644 index 00000000000..906bd06248d --- /dev/null +++ b/db/migrate/20201104204739_create_bulk_import_trackers.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class CreateBulkImportTrackers < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + with_lock_retries do + unless table_exists?(:bulk_import_trackers) + create_table :bulk_import_trackers do |t| + t.references :bulk_import_entity, + null: false, + index: false, + foreign_key: { on_delete: :cascade } + + t.text :relation, null: false + t.text :next_page + t.boolean :has_next_page, default: false, null: false + + t.index %w(bulk_import_entity_id relation), + unique: true, + name: :bulk_import_trackers_uniq_relation_by_entity + end + end + end + + add_check_constraint :bulk_import_trackers, + '(has_next_page IS FALSE or next_page IS NOT NULL)', + 'check_next_page_requirement' + add_text_limit :bulk_import_trackers, :relation, 255 + add_text_limit :bulk_import_trackers, :next_page, 255 + end + + def down + with_lock_retries do + drop_table :bulk_import_trackers + end + end +end diff --git a/db/migrate/20201105021637_add_uploads_size_to_project_statistics.rb b/db/migrate/20201105021637_add_uploads_size_to_project_statistics.rb new file mode 100644 index 00000000000..1d2251f6c37 --- /dev/null +++ b/db/migrate/20201105021637_add_uploads_size_to_project_statistics.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddUploadsSizeToProjectStatistics < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + add_column :project_statistics, :uploads_size, :bigint, default: 0, null: false + end + + def down + remove_column :project_statistics, :uploads_size + end +end diff --git a/db/migrate/20201105024127_add_uploads_size_to_namespace_root_storage_statistics.rb b/db/migrate/20201105024127_add_uploads_size_to_namespace_root_storage_statistics.rb new file mode 100644 index 00000000000..c3cccc7d5f2 --- /dev/null +++ b/db/migrate/20201105024127_add_uploads_size_to_namespace_root_storage_statistics.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddUploadsSizeToNamespaceRootStorageStatistics < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + add_column :namespace_root_storage_statistics, :uploads_size, :bigint, default: 0, null: false + end + + def down + remove_column :namespace_root_storage_statistics, :uploads_size + end +end diff --git a/db/migrate/20201105135051_change_default_value_of_ci_max_artifact_size_lsif_of_plan_limits_from20_to100.rb b/db/migrate/20201105135051_change_default_value_of_ci_max_artifact_size_lsif_of_plan_limits_from20_to100.rb new file mode 100644 index 00000000000..d53f81ecabb --- /dev/null +++ b/db/migrate/20201105135051_change_default_value_of_ci_max_artifact_size_lsif_of_plan_limits_from20_to100.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class ChangeDefaultValueOfCiMaxArtifactSizeLsifOfPlanLimitsFrom20To100 < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + change_column_default :plan_limits, :ci_max_artifact_size_lsif, 100 + execute('UPDATE plan_limits SET ci_max_artifact_size_lsif = 100 WHERE ci_max_artifact_size_lsif = 20') + end + end + + def down + with_lock_retries do + change_column_default :plan_limits, :ci_max_artifact_size_lsif, 20 + execute('UPDATE plan_limits SET ci_max_artifact_size_lsif = 20 WHERE ci_max_artifact_size_lsif = 100') + end + end +end diff --git a/db/migrate/20201105143211_add_vulnerabilities_enabled_and_issuetype_to_jira_tracker_data.rb b/db/migrate/20201105143211_add_vulnerabilities_enabled_and_issuetype_to_jira_tracker_data.rb new file mode 100644 index 00000000000..27269de611c --- /dev/null +++ b/db/migrate/20201105143211_add_vulnerabilities_enabled_and_issuetype_to_jira_tracker_data.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddVulnerabilitiesEnabledAndIssuetypeToJiraTrackerData < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20201105143312_add_text_limit_to_jira_tracker_data_issuetype.rb + def change + add_column :jira_tracker_data, :vulnerabilities_issuetype, :text + add_column :jira_tracker_data, :vulnerabilities_enabled, :boolean, default: false, null: false + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20201105143312_add_text_limit_to_jira_tracker_data_issuetype.rb b/db/migrate/20201105143312_add_text_limit_to_jira_tracker_data_issuetype.rb new file mode 100644 index 00000000000..4a81b0ce7af --- /dev/null +++ b/db/migrate/20201105143312_add_text_limit_to_jira_tracker_data_issuetype.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTextLimitToJiraTrackerDataIssuetype < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :jira_tracker_data, :vulnerabilities_issuetype, 255 + end + + def down + remove_text_limit :jira_tracker_data, :vulnerabilities_issuetype + end +end diff --git a/db/migrate/20201106134139_add_pipelines_created_index.rb b/db/migrate/20201106134139_add_pipelines_created_index.rb new file mode 100644 index 00000000000..aaf6643cf0b --- /dev/null +++ b/db/migrate/20201106134139_add_pipelines_created_index.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddPipelinesCreatedIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + INDEX_NAME = :index_ci_pipelines_on_project_id_and_status_and_created_at + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_pipelines, [:project_id, :status, :created_at], name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :ci_pipelines, INDEX_NAME + end +end diff --git a/db/migrate/20201107032257_add_default_true_require_admin_approval_after_user_signup_to_application_settings.rb b/db/migrate/20201107032257_add_default_true_require_admin_approval_after_user_signup_to_application_settings.rb new file mode 100644 index 00000000000..196f7bd8359 --- /dev/null +++ b/db/migrate/20201107032257_add_default_true_require_admin_approval_after_user_signup_to_application_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddDefaultTrueRequireAdminApprovalAfterUserSignupToApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + change_column_default :application_settings, :require_admin_approval_after_user_signup, from: false, to: true + end +end diff --git a/db/migrate/20201109144634_add_region_field_to_aws_role.rb b/db/migrate/20201109144634_add_region_field_to_aws_role.rb new file mode 100644 index 00000000000..ced75f24552 --- /dev/null +++ b/db/migrate/20201109144634_add_region_field_to_aws_role.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddRegionFieldToAwsRole < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless column_exists?(:aws_roles, :region) + add_column :aws_roles, :region, :text + end + + add_text_limit :aws_roles, :region, 255 + end + + def down + remove_column :aws_roles, :region + end +end diff --git a/db/migrate/20201109180311_add_secret_detection_revocation_token_types_application_settings.rb b/db/migrate/20201109180311_add_secret_detection_revocation_token_types_application_settings.rb new file mode 100644 index 00000000000..0823655f92f --- /dev/null +++ b/db/migrate/20201109180311_add_secret_detection_revocation_token_types_application_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddSecretDetectionRevocationTokenTypesApplicationSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + add_column :application_settings, :secret_detection_revocation_token_types_url, :text, null: true # rubocop:disable Migration/AddLimitToTextColumns + end + + def down + remove_column :application_settings, :secret_detection_revocation_token_types_url + end +end diff --git a/db/migrate/20201109184023_add_text_limit_to_secret_detection_revocation_token_types_application_settings.rb b/db/migrate/20201109184023_add_text_limit_to_secret_detection_revocation_token_types_application_settings.rb new file mode 100644 index 00000000000..9e0329aafcc --- /dev/null +++ b/db/migrate/20201109184023_add_text_limit_to_secret_detection_revocation_token_types_application_settings.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddTextLimitToSecretDetectionRevocationTokenTypesApplicationSettings < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :secret_detection_revocation_token_types_url, 255 + end + + def down + remove_text_limit :application_settings, :secret_detection_revocation_token_types_url + end +end diff --git a/db/migrate/20201110035029_created_index_for_vulnerability_occurrences_on_project_fingerprint.rb b/db/migrate/20201110035029_created_index_for_vulnerability_occurrences_on_project_fingerprint.rb new file mode 100644 index 00000000000..fed117d5f08 --- /dev/null +++ b/db/migrate/20201110035029_created_index_for_vulnerability_occurrences_on_project_fingerprint.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreatedIndexForVulnerabilityOccurrencesOnProjectFingerprint < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + INDEX_NAME = 'index_vulnerability_occurrences_on_project_fingerprint' + + disable_ddl_transaction! + + def up + add_concurrent_index :vulnerability_occurrences, :project_fingerprint, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :vulnerability_occurrences, INDEX_NAME + end +end diff --git a/db/migrate/20201110110454_extend_postgres_indexes_view.rb b/db/migrate/20201110110454_extend_postgres_indexes_view.rb new file mode 100644 index 00000000000..4e9172024d3 --- /dev/null +++ b/db/migrate/20201110110454_extend_postgres_indexes_view.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +class ExtendPostgresIndexesView < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + execute(<<~SQL) + DROP VIEW postgres_indexes; + + CREATE VIEW postgres_indexes AS + SELECT (pg_namespace.nspname::text || '.'::text) || pg_class.relname::text AS identifier, + pg_index.indexrelid, + pg_namespace.nspname AS schema, + pg_class.relname AS name, + pg_index.indisunique AS "unique", + pg_index.indisvalid AS valid_index, + pg_class.relispartition AS partitioned, + pg_index.indisexclusion AS exclusion, + pg_index.indexprs IS NOT NULL as expression, + pg_index.indpred IS NOT NULL as partial, + pg_indexes.indexdef AS definition, + pg_relation_size(pg_class.oid::regclass) AS ondisk_size_bytes + FROM pg_index + JOIN pg_class ON pg_class.oid = pg_index.indexrelid + JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid + JOIN pg_indexes ON pg_class.relname = pg_indexes.indexname + WHERE pg_namespace.nspname <> 'pg_catalog'::name + AND (pg_namespace.nspname = ANY (ARRAY["current_schema"(), 'gitlab_partitions_dynamic'::name, 'gitlab_partitions_static'::name])); + SQL + end + + def down + execute(<<~SQL) + DROP VIEW postgres_indexes; + + CREATE VIEW postgres_indexes AS + SELECT (pg_namespace.nspname::text || '.'::text) || pg_class.relname::text AS identifier, + pg_index.indexrelid, + pg_namespace.nspname AS schema, + pg_class.relname AS name, + pg_index.indisunique AS "unique", + pg_index.indisvalid AS valid_index, + pg_class.relispartition AS partitioned, + pg_index.indisexclusion AS exclusion, + pg_indexes.indexdef AS definition, + pg_relation_size(pg_class.oid::regclass) AS ondisk_size_bytes + FROM pg_index + JOIN pg_class ON pg_class.oid = pg_index.indexrelid + JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid + JOIN pg_indexes ON pg_class.relname = pg_indexes.indexname + WHERE pg_namespace.nspname <> 'pg_catalog'::name + AND (pg_namespace.nspname = ANY (ARRAY["current_schema"(), 'gitlab_partitions_dynamic'::name, 'gitlab_partitions_static'::name])); + SQL + end +end diff --git a/db/migrate/20201110133629_change_index_mr_metrics_target_project_id.rb b/db/migrate/20201110133629_change_index_mr_metrics_target_project_id.rb new file mode 100644 index 00000000000..5bd810207d8 --- /dev/null +++ b/db/migrate/20201110133629_change_index_mr_metrics_target_project_id.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class ChangeIndexMrMetricsTargetProjectId < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + INDEX_NAME = 'index_merge_request_metrics_on_target_project_id_merged_at' + NULLS_LAST_INDEX_NAME = 'index_mr_metrics_on_target_project_id_merged_at_nulls_last' + + def up + add_concurrent_index :merge_request_metrics, [:target_project_id, :merged_at, :id], order: { merged_at: 'DESC NULLS LAST', id: 'DESC' }, name: NULLS_LAST_INDEX_NAME + remove_concurrent_index_by_name(:merge_request_metrics, INDEX_NAME) + end + + def down + add_concurrent_index :merge_request_metrics, [:target_project_id, :merged_at], name: INDEX_NAME + remove_concurrent_index_by_name(:merge_request_metrics, NULLS_LAST_INDEX_NAME) + end +end diff --git a/db/migrate/20201111110318_add_cloud_license_auth_token_to_settings.rb b/db/migrate/20201111110318_add_cloud_license_auth_token_to_settings.rb new file mode 100644 index 00000000000..e2069835597 --- /dev/null +++ b/db/migrate/20201111110318_add_cloud_license_auth_token_to_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddCloudLicenseAuthTokenToSettings < ActiveRecord::Migration[6.0] + DOWNTIME = false + + # rubocop:disable Migration/AddLimitToTextColumns + # limit is added in 20201111110918_add_cloud_license_auth_token_application_settings_text_limit + def change + add_column :application_settings, :encrypted_cloud_license_auth_token, :text + add_column :application_settings, :encrypted_cloud_license_auth_token_iv, :text + end + # rubocop:enable Migration/AddLimitToTextColumns +end diff --git a/db/migrate/20201111110918_add_cloud_license_auth_token_application_settings_text_limit.rb b/db/migrate/20201111110918_add_cloud_license_auth_token_application_settings_text_limit.rb new file mode 100644 index 00000000000..fd1ee5e07bf --- /dev/null +++ b/db/migrate/20201111110918_add_cloud_license_auth_token_application_settings_text_limit.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddCloudLicenseAuthTokenApplicationSettingsTextLimit < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :application_settings, :encrypted_cloud_license_auth_token_iv, 255 + end + + def down + remove_text_limit :application_settings, :encrypted_cloud_license_auth_token_iv + end +end diff --git a/db/migrate/20201111152859_add_missing_expression_indexes.rb b/db/migrate/20201111152859_add_missing_expression_indexes.rb new file mode 100644 index 00000000000..e2742f7f3bc --- /dev/null +++ b/db/migrate/20201111152859_add_missing_expression_indexes.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class AddMissingExpressionIndexes < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + INDEXES = [ + [:namespaces, :index_on_namespaces_lower_name, 'LOWER(name)'], + [:namespaces, :index_on_namespaces_lower_path, 'LOWER(path)'], + [:projects, :index_on_projects_lower_path, 'LOWER(path)'], + [:routes, :index_on_routes_lower_path, 'LOWER(path)'], + [:users, :index_on_users_lower_username, 'LOWER(username)'], + [:users, :index_on_users_lower_email, 'LOWER(email)'] + ] + + def up + # Those indexes had been introduced before, but they haven't been + # captured in structure.sql. For installations that already have it, + # this is a no-op - others will get it retroactively with + # this migration. + + tables = Set.new + + INDEXES.each do |(table, name, expression)| + unless index_name_exists?(table, name) + add_concurrent_index table, expression, name: name + tables.add(table) + end + end + + # Rebuild statistics on affected tables only + tables.each do |table| + execute("ANALYZE #{table}") + end + end + + def down + # no-op + end +end diff --git a/db/migrate/20201112195322_reseed_merge_trains_enabled.rb b/db/migrate/20201112195322_reseed_merge_trains_enabled.rb new file mode 100644 index 00000000000..777c59d16b1 --- /dev/null +++ b/db/migrate/20201112195322_reseed_merge_trains_enabled.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ReseedMergeTrainsEnabled < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + update_column_in_batches(:project_ci_cd_settings, :merge_trains_enabled, true) do |table, query| + query.where(table[:merge_pipelines_enabled].eq(true)) + end + end + + def down + # no-op + end +end -- cgit v1.2.1