diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-06 21:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-06 21:08:40 +0300 |
commit | 1f5e09ed6082d079dfebef92f69630c10f78c844 (patch) | |
tree | 5ef925fe6d08f2a042e47c2a9e1c40238ca8211c /db | |
parent | 78782cd1eb5273265668ca3e438bb8cbb1344004 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
7 files changed, 121 insertions, 4 deletions
diff --git a/db/migrate/20230405102815_add_unique_namespace_index_to_storage_limit_exclusions.rb b/db/migrate/20230405102815_add_unique_namespace_index_to_storage_limit_exclusions.rb new file mode 100644 index 00000000000..d732fb35ce9 --- /dev/null +++ b/db/migrate/20230405102815_add_unique_namespace_index_to_storage_limit_exclusions.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddUniqueNamespaceIndexToStorageLimitExclusions < Gitlab::Database::Migration[2.1] + TABLE_NAME = 'namespaces_storage_limit_exclusions' + OLD_INDEX_NAME = 'index_namespaces_storage_limit_exclusions_on_namespace_id' + NEW_INDEX_NAME = 'unique_idx_namespaces_storage_limit_exclusions_on_namespace_id' + + disable_ddl_transaction! + + def up + add_concurrent_index TABLE_NAME, :namespace_id, + unique: true, + name: NEW_INDEX_NAME + + remove_concurrent_index_by_name TABLE_NAME, OLD_INDEX_NAME + end + + def down + add_concurrent_index TABLE_NAME, :namespace_id, + unique: false, + name: OLD_INDEX_NAME + + remove_concurrent_index_by_name TABLE_NAME, NEW_INDEX_NAME + end +end diff --git a/db/post_migrate/20230404023648_ensure_suggestions_note_id_bigint_backfill_is_finished_for_gitlab_dot_com.rb b/db/post_migrate/20230404023648_ensure_suggestions_note_id_bigint_backfill_is_finished_for_gitlab_dot_com.rb new file mode 100644 index 00000000000..adf33df6fc2 --- /dev/null +++ b/db/post_migrate/20230404023648_ensure_suggestions_note_id_bigint_backfill_is_finished_for_gitlab_dot_com.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class EnsureSuggestionsNoteIdBigintBackfillIsFinishedForGitlabDotCom < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + restrict_gitlab_migration gitlab_schema: :gitlab_main + disable_ddl_transaction! + + def up + return unless should_run? + + ensure_batched_background_migration_is_finished( + job_class_name: 'CopyColumnUsingBackgroundMigrationJob', + table_name: 'suggestions', + column_name: 'id', + job_arguments: [['note_id'], ['note_id_convert_to_bigint']] + ) + end + + def down + # no-op + end + + private + + def should_run? + com_or_dev_or_test_but_not_jh? + end +end diff --git a/db/post_migrate/20230404023915_swap_suggestions_note_id_to_bigint_for_gitlab_dot_com.rb b/db/post_migrate/20230404023915_swap_suggestions_note_id_to_bigint_for_gitlab_dot_com.rb new file mode 100644 index 00000000000..fb5c379c015 --- /dev/null +++ b/db/post_migrate/20230404023915_swap_suggestions_note_id_to_bigint_for_gitlab_dot_com.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +class SwapSuggestionsNoteIdToBigintForGitlabDotCom < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + disable_ddl_transaction! + + TABLE_NAME = 'suggestions' + + def up + return unless should_run? + + swap + end + + def down + return unless should_run? + + swap + end + + def swap + # This will replace the existing index_suggestions_on_note_id_and_relative_order + add_concurrent_index TABLE_NAME, [:note_id_convert_to_bigint, :relative_order], unique: true, + name: 'index_suggestions_on_note_id_convert_to_bigint_relative_order' + + # This will replace the existing fk_rails_33b03a535c + add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint, + name: 'fk_suggestions_note_id_convert_to_bigint', + on_delete: :cascade + + with_lock_retries(raise_on_exhaustion: true) do + execute "LOCK TABLE notes, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" + + execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id TO note_id_tmp" + execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_convert_to_bigint TO note_id" + execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_tmp TO note_id_convert_to_bigint" + + function_name = Gitlab::Database::UnidirectionalCopyTrigger + .on_table(TABLE_NAME, connection: connection) + .name(:note_id, :note_id_convert_to_bigint) + execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" + + # Swap defaults + change_column_default TABLE_NAME, :note_id, nil + change_column_default TABLE_NAME, :note_id_convert_to_bigint, 0 + + execute 'DROP INDEX IF EXISTS index_suggestions_on_note_id_and_relative_order' + rename_index TABLE_NAME, 'index_suggestions_on_note_id_convert_to_bigint_relative_order', + 'index_suggestions_on_note_id_and_relative_order' + + execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_33b03a535c" + rename_constraint(TABLE_NAME, 'fk_suggestions_note_id_convert_to_bigint', 'fk_rails_33b03a535c') + end + end + + def should_run? + com_or_dev_or_test_but_not_jh? + end +end diff --git a/db/schema_migrations/20230404023648 b/db/schema_migrations/20230404023648 new file mode 100644 index 00000000000..c9ac5581cf3 --- /dev/null +++ b/db/schema_migrations/20230404023648 @@ -0,0 +1 @@ +ef9f641608397a12e6b5384667194a8b3e5b929c76c365105f47fd00c5c7f219
\ No newline at end of file diff --git a/db/schema_migrations/20230404023915 b/db/schema_migrations/20230404023915 new file mode 100644 index 00000000000..99d7f3ec63c --- /dev/null +++ b/db/schema_migrations/20230404023915 @@ -0,0 +1 @@ +20bfe6e7faf02d4b20babf0f80d51bfd3618f3fd1faf512af948f1976d8c5838
\ No newline at end of file diff --git a/db/schema_migrations/20230405102815 b/db/schema_migrations/20230405102815 new file mode 100644 index 00000000000..a5c8f90fe6b --- /dev/null +++ b/db/schema_migrations/20230405102815 @@ -0,0 +1 @@ +60ae9405a4d4f4c41abc0b6b29c557701ae10957622297d093c70fade32e2863
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 352ff598cb5..ff48cb12b75 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -22746,7 +22746,7 @@ ALTER SEQUENCE subscriptions_id_seq OWNED BY subscriptions.id; CREATE TABLE suggestions ( id bigint NOT NULL, - note_id integer NOT NULL, + note_id_convert_to_bigint integer DEFAULT 0 NOT NULL, relative_order smallint NOT NULL, applied boolean DEFAULT false NOT NULL, commit_id character varying, @@ -22755,7 +22755,7 @@ CREATE TABLE suggestions ( lines_above integer DEFAULT 0 NOT NULL, lines_below integer DEFAULT 0 NOT NULL, outdated boolean DEFAULT false NOT NULL, - note_id_convert_to_bigint bigint DEFAULT 0 NOT NULL + note_id bigint NOT NULL ); CREATE SEQUENCE suggestions_id_seq @@ -31260,8 +31260,6 @@ CREATE INDEX index_namespaces_on_updated_at ON namespaces USING btree (updated_a CREATE INDEX index_namespaces_public_groups_name_id ON namespaces USING btree (name, id) WHERE (((type)::text = 'Group'::text) AND (visibility_level = 20)); -CREATE INDEX index_namespaces_storage_limit_exclusions_on_namespace_id ON namespaces_storage_limit_exclusions USING btree (namespace_id); - CREATE INDEX index_namespaces_sync_events_on_namespace_id ON namespaces_sync_events USING btree (namespace_id); CREATE INDEX index_next_over_limit_check_at_asc_order ON namespace_details USING btree (next_over_limit_check_at NULLS FIRST); @@ -32872,6 +32870,8 @@ CREATE UNIQUE INDEX uniq_pkgs_debian_project_distributions_project_id_and_suite CREATE UNIQUE INDEX unique_ci_builds_token_encrypted_and_partition_id ON ci_builds USING btree (token_encrypted, partition_id) WHERE (token_encrypted IS NOT NULL); +CREATE UNIQUE INDEX unique_idx_namespaces_storage_limit_exclusions_on_namespace_id ON namespaces_storage_limit_exclusions USING btree (namespace_id); + CREATE UNIQUE INDEX unique_index_ci_build_pending_states_on_partition_id_build_id ON ci_build_pending_states USING btree (partition_id, build_id); CREATE UNIQUE INDEX unique_index_for_project_pages_unique_domain ON project_settings USING btree (pages_unique_domain) WHERE (pages_unique_domain IS NOT NULL); |