diff --git a/db/migrate/20251210175841_add_organization_id_to_web_hook_logs_daily.rb b/db/migrate/20251210175841_add_organization_id_to_web_hook_logs_daily.rb new file mode 100644 index 0000000000000000000000000000000000000000..54e37213ba326065ecb960a07095467255f8f6f0 --- /dev/null +++ b/db/migrate/20251210175841_add_organization_id_to_web_hook_logs_daily.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddOrganizationIdToWebHookLogsDaily < Gitlab::Database::Migration[2.3] + milestone '18.8' + + def change + # rubocop:disable Migration/PreventAddingColumns -- required for sharding + add_column :web_hook_logs_daily, :organization_id, :bigint, if_not_exists: true + # rubocop:enable Migration/PreventAddingColumns + end +end diff --git a/db/migrate/20251210175842_add_group_id_to_web_hook_logs_daily.rb b/db/migrate/20251210175842_add_group_id_to_web_hook_logs_daily.rb new file mode 100644 index 0000000000000000000000000000000000000000..b044a83c7a2c101839a55d57957d56b2dddc327e --- /dev/null +++ b/db/migrate/20251210175842_add_group_id_to_web_hook_logs_daily.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddGroupIdToWebHookLogsDaily < Gitlab::Database::Migration[2.3] + milestone '18.8' + + def change + # rubocop:disable Migration/PreventAddingColumns -- required for sharding + add_column :web_hook_logs_daily, :group_id, :bigint, if_not_exists: true + # rubocop:enable Migration/PreventAddingColumns + end +end diff --git a/db/migrate/20251210175843_add_project_id_to_web_hook_logs_daily.rb b/db/migrate/20251210175843_add_project_id_to_web_hook_logs_daily.rb new file mode 100644 index 0000000000000000000000000000000000000000..dc13859e35abd1280cf6ecb1688593b41f5d8764 --- /dev/null +++ b/db/migrate/20251210175843_add_project_id_to_web_hook_logs_daily.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddProjectIdToWebHookLogsDaily < Gitlab::Database::Migration[2.3] + milestone '18.8' + + def change + # rubocop:disable Migration/PreventAddingColumns -- required for sharding + add_column :web_hook_logs_daily, :project_id, :bigint, if_not_exists: true + # rubocop:enable Migration/PreventAddingColumns + end +end diff --git a/db/post_migrate/20251210180245_prepare_async_index_web_hook_logs_daily_on_organization_id.rb b/db/post_migrate/20251210180245_prepare_async_index_web_hook_logs_daily_on_organization_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..3f96c01a3d1393794f963518183ae2f70747f852 --- /dev/null +++ b/db/post_migrate/20251210180245_prepare_async_index_web_hook_logs_daily_on_organization_id.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class PrepareAsyncIndexWebHookLogsDailyOnOrganizationId < Gitlab::Database::Migration[2.3] + include Gitlab::Database::PartitioningMigrationHelpers + + milestone '18.8' + disable_ddl_transaction! + + PARTITIONED_INDEX_NAME = 'index_web_hook_logs_daily_on_organization_id' + + def up + # rubocop:disable Migration/PreventIndexCreation -- required for sharding + prepare_partitioned_async_index :web_hook_logs_daily, :organization_id, name: PARTITIONED_INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation + end + + def down + unprepare_partitioned_async_index :web_hook_logs_daily, PARTITIONED_INDEX_NAME + end +end diff --git a/db/post_migrate/20251210180531_prepare_async_index_web_hook_logs_daily_on_group_id.rb b/db/post_migrate/20251210180531_prepare_async_index_web_hook_logs_daily_on_group_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..0d870e0e774c43a23f105e4eed55bd5c6df30f2d --- /dev/null +++ b/db/post_migrate/20251210180531_prepare_async_index_web_hook_logs_daily_on_group_id.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class PrepareAsyncIndexWebHookLogsDailyOnGroupId < Gitlab::Database::Migration[2.3] + include Gitlab::Database::PartitioningMigrationHelpers + + milestone '18.8' + disable_ddl_transaction! + + PARTITIONED_INDEX_NAME = 'index_web_hook_logs_daily_on_group_id' + + def up + # rubocop:disable Migration/PreventIndexCreation -- required for sharding + prepare_partitioned_async_index :web_hook_logs_daily, :group_id, name: PARTITIONED_INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation + end + + def down + unprepare_partitioned_async_index :web_hook_logs_daily, PARTITIONED_INDEX_NAME + end +end diff --git a/db/post_migrate/20251210180643_prepare_async_index_web_hook_logs_daily_on_project_id.rb b/db/post_migrate/20251210180643_prepare_async_index_web_hook_logs_daily_on_project_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..533238b67ae58386409bc7104b163f7ccd1ccbba --- /dev/null +++ b/db/post_migrate/20251210180643_prepare_async_index_web_hook_logs_daily_on_project_id.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class PrepareAsyncIndexWebHookLogsDailyOnProjectId < Gitlab::Database::Migration[2.3] + include Gitlab::Database::PartitioningMigrationHelpers + + milestone '18.8' + disable_ddl_transaction! + + PARTITIONED_INDEX_NAME = 'index_web_hook_logs_daily_on_project_id' + + def up + # rubocop:disable Migration/PreventIndexCreation -- required for sharding + prepare_partitioned_async_index :web_hook_logs_daily, :project_id, name: PARTITIONED_INDEX_NAME + # rubocop:enable Migration/PreventIndexCreation + end + + def down + unprepare_partitioned_async_index :web_hook_logs_daily, PARTITIONED_INDEX_NAME + end +end diff --git a/db/schema_migrations/20251210175841 b/db/schema_migrations/20251210175841 new file mode 100644 index 0000000000000000000000000000000000000000..309957465297ec870151751ffed61ce73e001583 --- /dev/null +++ b/db/schema_migrations/20251210175841 @@ -0,0 +1 @@ +b3462a58962530ec9d45480031d887260cd122393b80554f9a14505381db71d0 \ No newline at end of file diff --git a/db/schema_migrations/20251210175842 b/db/schema_migrations/20251210175842 new file mode 100644 index 0000000000000000000000000000000000000000..02f07d06a40750c50e4a2eb3bbfffa636f9ef18a --- /dev/null +++ b/db/schema_migrations/20251210175842 @@ -0,0 +1 @@ +b4de00e7bcc13ce2e568a5195483b301a59215bb7dedf94064a145ad630d4ab7 \ No newline at end of file diff --git a/db/schema_migrations/20251210175843 b/db/schema_migrations/20251210175843 new file mode 100644 index 0000000000000000000000000000000000000000..33280a65ba7d67c0679f9bf6a733863fa311481a --- /dev/null +++ b/db/schema_migrations/20251210175843 @@ -0,0 +1 @@ +9a001c47565d6c3968e0627fcad98e378a09a0a42c8063d7b613fb7e2a56094b \ No newline at end of file diff --git a/db/schema_migrations/20251210180245 b/db/schema_migrations/20251210180245 new file mode 100644 index 0000000000000000000000000000000000000000..afe8104cd50358cf84ca870bd7d1e33274f6eb90 --- /dev/null +++ b/db/schema_migrations/20251210180245 @@ -0,0 +1 @@ +87e7602a6e4f866b0d1db747ac63e5410263911d938ab91322286fe93071f8ee \ No newline at end of file diff --git a/db/schema_migrations/20251210180531 b/db/schema_migrations/20251210180531 new file mode 100644 index 0000000000000000000000000000000000000000..7260b0ccd522a3659ba8d9c90015268a298868ef --- /dev/null +++ b/db/schema_migrations/20251210180531 @@ -0,0 +1 @@ +9cdf916ae5d5c34e9e4900182bcda7c4ae413f914f559579f7f80787afc774c4 \ No newline at end of file diff --git a/db/schema_migrations/20251210180643 b/db/schema_migrations/20251210180643 new file mode 100644 index 0000000000000000000000000000000000000000..320bf02b75d839ddef4b533d236deacfff78a579 --- /dev/null +++ b/db/schema_migrations/20251210180643 @@ -0,0 +1 @@ +94e0ffa878280d0d4f0ced81ca0851d851fc1eced3f3bbdd061d30a8d490ba38 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 7809a7aedda1f67e53e1e54ad73b7791b2ad0ea9..73b534f6f706e654bcaf00735f84716b2a2479ab 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -6347,6 +6347,9 @@ CREATE TABLE web_hook_logs_daily ( updated_at timestamp without time zone NOT NULL, created_at timestamp without time zone NOT NULL, url_hash text, + organization_id bigint, + group_id bigint, + project_id bigint, CONSTRAINT check_df72cb58f5 CHECK ((char_length(url_hash) <= 44)) ) PARTITION BY RANGE (created_at); diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index f004d5a92d768991cfeb30fe13798ae040204317..1131df8c5e031fd8ca6d50dffdf48b46329a6682 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -247,7 +247,7 @@ # See: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87584 # Fixes performance issues with the deletion of web-hooks with many log entries web_hook_logs: %w[web_hook_id], - web_hook_logs_daily: %w[web_hook_id], + web_hook_logs_daily: %w[web_hook_id organization_id group_id project_id], ml_candidates: %w[internal_id], value_stream_dashboard_counts: %w[namespace_id], vulnerability_export_parts: %w[start_id end_id], diff --git a/spec/lib/gitlab/organizations/sharding_key_spec.rb b/spec/lib/gitlab/organizations/sharding_key_spec.rb index 9841713eb42e28a3e1d50f89bbeb2fdc2ff94ac9..02dbc6d7e1a26a16fa14b646c7b74551dbb765c0 100644 --- a/spec/lib/gitlab/organizations/sharding_key_spec.rb +++ b/spec/lib/gitlab/organizations/sharding_key_spec.rb @@ -257,6 +257,7 @@ "fork_networks" => "https://gitlab.com/gitlab-org/gitlab/-/issues/522958", "bulk_import_configurations" => "https://gitlab.com/gitlab-org/gitlab/-/issues/536521", "pool_repositories" => "https://gitlab.com/gitlab-org/gitlab/-/issues/490484", + "web_hook_logs_daily" => "https://gitlab.com/gitlab-org/gitlab/-/work_items/524820", # All the tables below related to uploads are part of the same work to # add sharding key to the table "admin_roles" => "https://gitlab.com/gitlab-org/gitlab/-/issues/553437",