diff --git a/db/post_migrate/20251215180743_validate_not_null_constraint_on_spam_logs_for_user_id.rb b/db/post_migrate/20251215180743_validate_not_null_constraint_on_spam_logs_for_user_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..803360cfb13e984376502d2179b91b00afbbd7a4 --- /dev/null +++ b/db/post_migrate/20251215180743_validate_not_null_constraint_on_spam_logs_for_user_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ValidateNotNullConstraintOnSpamLogsForUserId < Gitlab::Database::Migration[2.3] + milestone '18.8' + + def up + validate_not_null_constraint :spam_logs, :user_id, constraint_name: "check_56d1d910ee" + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20251215180745_validate_foreign_key_constraint_on_spam_logs_for_user_id.rb b/db/post_migrate/20251215180745_validate_foreign_key_constraint_on_spam_logs_for_user_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..88ab565796afa1814b172d0bf9b6ce8b786b411a --- /dev/null +++ b/db/post_migrate/20251215180745_validate_foreign_key_constraint_on_spam_logs_for_user_id.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ValidateForeignKeyConstraintOnSpamLogsForUserId < Gitlab::Database::Migration[2.3] + milestone '18.8' + + def up + validate_foreign_key :spam_logs, :user_id, name: 'fk_1cb83308b1' + end + + def down + # no-op + end +end diff --git a/db/schema_migrations/20251215180743 b/db/schema_migrations/20251215180743 new file mode 100644 index 0000000000000000000000000000000000000000..7b05ea279c09ce3d3c4d16f7b375f3850db1510e --- /dev/null +++ b/db/schema_migrations/20251215180743 @@ -0,0 +1 @@ +2e56a8a912918b634b92153d1ab852a4b137c61088db2a790ab25bd76a916d02 \ No newline at end of file diff --git a/db/schema_migrations/20251215180745 b/db/schema_migrations/20251215180745 new file mode 100644 index 0000000000000000000000000000000000000000..0b9e9cb83aa6483f11175656ac3f030e8fd1984e --- /dev/null +++ b/db/schema_migrations/20251215180745 @@ -0,0 +1 @@ +25b9f50f211266f92b03e21d0d8f83bcb9cfe6730e24cd7c466995060b83c769 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 6746648605376e984366abac822589d883ff7cbb..47a43bcd3f7490f3f8ac7fdbb687202c629b8151 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -27652,7 +27652,8 @@ CREATE TABLE spam_logs ( submitted_as_ham boolean DEFAULT false NOT NULL, recaptcha_verified boolean DEFAULT false NOT NULL, target_id bigint, - organization_id bigint + organization_id bigint, + CONSTRAINT check_56d1d910ee CHECK ((user_id IS NOT NULL)) ); CREATE SEQUENCE spam_logs_id_seq @@ -35075,9 +35076,6 @@ ALTER TABLE user_details ALTER TABLE diff_note_positions ADD CONSTRAINT check_4c86140f48 CHECK ((namespace_id IS NOT NULL)) NOT VALID; -ALTER TABLE spam_logs - ADD CONSTRAINT check_56d1d910ee CHECK ((user_id IS NOT NULL)) NOT VALID; - ALTER TABLE ONLY instance_type_ci_runners ADD CONSTRAINT check_5c34a3c1db UNIQUE (id); @@ -50155,7 +50153,7 @@ ALTER TABLE ONLY approval_policy_rule_project_links ADD CONSTRAINT fk_1c78796d52 FOREIGN KEY (approval_policy_rule_id) REFERENCES approval_policy_rules(id) ON DELETE CASCADE; ALTER TABLE ONLY spam_logs - ADD CONSTRAINT fk_1cb83308b1 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE NOT VALID; + ADD CONSTRAINT fk_1cb83308b1 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; ALTER TABLE ONLY issue_links ADD CONSTRAINT fk_1cce06b868 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; diff --git a/ee/spec/lib/gitlab/database/desired_sharding_key_spec.rb b/ee/spec/lib/gitlab/database/desired_sharding_key_spec.rb index d115649ae05309e7114e9ba43eb253bf7b723c1a..fff75fa656e7f12e06a9cf635dc52c4ee250fc23 100644 --- a/ee/spec/lib/gitlab/database/desired_sharding_key_spec.rb +++ b/ee/spec/lib/gitlab/database/desired_sharding_key_spec.rb @@ -23,7 +23,6 @@ 'design_management_versions.issue_id', # https://gitlab.com/gitlab-org/gitlab/-/issues/461330 'requirements_management_test_reports.issue_id', # https://gitlab.com/gitlab-org/gitlab/-/issues/383031 # We nullify the FK once the parent is deleted and remove entries using a cleanup worker. - 'spam_logs.user_id', 'packages_nuget_symbols.package_id' ] end