diff --git a/db/migrate/20230718094246_add_namespace_id_to_notes.rb b/db/migrate/20230718094246_add_namespace_id_to_notes.rb new file mode 100644 index 0000000000000000000000000000000000000000..f2f3ef401a4f4ca6c9ecbd831802769dc1bcb808 --- /dev/null +++ b/db/migrate/20230718094246_add_namespace_id_to_notes.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddNamespaceIdToNotes < Gitlab::Database::Migration[2.1] + enable_lock_retries! + + def up + add_column :notes, :namespace_id, :bigint + end + + def down + remove_column :notes, :namespace_id + end +end diff --git a/db/post_migrate/20230718094501_prepare_notes_namespace_id_index.rb b/db/post_migrate/20230718094501_prepare_notes_namespace_id_index.rb new file mode 100644 index 0000000000000000000000000000000000000000..41f57814c4122ceb16a599f2881e4d22484452d6 --- /dev/null +++ b/db/post_migrate/20230718094501_prepare_notes_namespace_id_index.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class PrepareNotesNamespaceIdIndex < Gitlab::Database::Migration[2.1] + INDEX_NAME = 'index_notes_on_namespace_id' + + # TODO: Index to be created synchronously as part of https://gitlab.com/gitlab-org/gitlab/-/issues/416127 + def up + prepare_async_index :notes, :namespace_id, name: INDEX_NAME + end + + def down + unprepare_async_index :notes, :namespace_id, name: INDEX_NAME + end +end diff --git a/db/schema_migrations/20230718094246 b/db/schema_migrations/20230718094246 new file mode 100644 index 0000000000000000000000000000000000000000..4d42af51f7d8624b82ff617bb87e829d167d7d5e --- /dev/null +++ b/db/schema_migrations/20230718094246 @@ -0,0 +1 @@ +8cb2cd90109dcc4f29ab34fa4caca617fe7bf42493e3a6712b66978480f06940 \ No newline at end of file diff --git a/db/schema_migrations/20230718094501 b/db/schema_migrations/20230718094501 new file mode 100644 index 0000000000000000000000000000000000000000..3db259aa8ba60ffa7284eead8b500e620f62caa0 --- /dev/null +++ b/db/schema_migrations/20230718094501 @@ -0,0 +1 @@ +636bd7305c03f94cd161dc21deda05c289946b31a3c04805c08273f9a7067729 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index fc0b145ad3823f7c5d5c79d3681f531dddabb8a7..c78381494225521f5102548502bf01f308ac2221 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -19080,7 +19080,8 @@ CREATE TABLE notes ( confidential boolean, last_edited_at timestamp with time zone, internal boolean DEFAULT false NOT NULL, - id bigint NOT NULL + id bigint NOT NULL, + namespace_id bigint ); CREATE SEQUENCE notes_id_seq diff --git a/lib/gitlab/import_export/project/import_export.yml b/lib/gitlab/import_export/project/import_export.yml index 5986c5de4415b9681cc076893659b6bf30c13421..850c89c1fb1e379e2e7b2fb6df9e1f665aba8ce9 100644 --- a/lib/gitlab/import_export/project/import_export.yml +++ b/lib/gitlab/import_export/project/import_export.yml @@ -984,9 +984,11 @@ excluded_attributes: notes: - :noteable_id - :review_id + - :namespace_id commit_notes: - :noteable_id - :review_id + - :namespace_id label_links: - :label_id - :target_id diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index c22292cb82c6c446450518a618fa0e08832c4a56..bb50c7cf69d18f3838ecbb0d0fce6bf8543e5a22 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -14,7 +14,8 @@ # but in Search::NamespaceIndexAssignment model, only `search_index_id` is used as foreign key and indexed search_namespace_index_assignments: [%w[search_index_id index_type]], slack_integrations_scopes: [%w[slack_api_scope_id]], - namespaces: %w[organization_id] # this index is added in an async manner, hence it needs to be ignored in the first phase. + namespaces: %w[organization_id], # this index is added in an async manner, hence it needs to be ignored in the first phase. + notes: %w[namespace_id] # this index is added in an async manner, hence it needs to be ignored in the first phase. }.with_indifferent_access.freeze TABLE_PARTITIONS = %w[ci_builds_metadata].freeze @@ -82,7 +83,7 @@ merge_requests_compliance_violations: %w[target_project_id], merge_request_diff_commits: %w[commit_author_id committer_id], namespaces: %w[owner_id parent_id], - notes: %w[author_id commit_id noteable_id updated_by_id resolved_by_id confirmed_by_id discussion_id], + notes: %w[author_id commit_id noteable_id updated_by_id resolved_by_id confirmed_by_id discussion_id namespace_id], notification_settings: %w[source_id], oauth_access_grants: %w[resource_owner_id application_id], oauth_access_tokens: %w[resource_owner_id application_id],