diff --git a/db/post_migrate/20251215205262_finalize_user_agent_details_organization_id_backfill.rb b/db/post_migrate/20251215205262_finalize_user_agent_details_organization_id_backfill.rb new file mode 100644 index 0000000000000000000000000000000000000000..660c4fc3e260294fd12e771c7c64b4bef2dbaf5e --- /dev/null +++ b/db/post_migrate/20251215205262_finalize_user_agent_details_organization_id_backfill.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class FinalizeUserAgentDetailsOrganizationIdBackfill < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.9' + restrict_gitlab_migration gitlab_schema: :gitlab_main_org + + MIGRATION = 'BackfillUserAgentDetailsOrganizationId' + + def up + ensure_batched_background_migration_is_finished( + job_class_name: MIGRATION, + table_name: :user_agent_details, + column_name: :id, + job_arguments: [], + finalize: true + ) + end + + def down + # no-op + end +end diff --git a/db/post_migrate/20251215205265_add_not_null_constraint_to_user_agent_details_on_organization_id.rb b/db/post_migrate/20251215205265_add_not_null_constraint_to_user_agent_details_on_organization_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..b87793dade4f615182812ce60b0cd78ac7b23f01 --- /dev/null +++ b/db/post_migrate/20251215205265_add_not_null_constraint_to_user_agent_details_on_organization_id.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddNotNullConstraintToUserAgentDetailsOnOrganizationId < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.9' + + def up + add_not_null_constraint :user_agent_details, :organization_id, validate: false + end + + def down + remove_not_null_constraint :user_agent_details, :organization_id + end +end diff --git a/db/post_migrate/20251215205270_prepare_user_agent_details_organization_id_not_null_validation.rb b/db/post_migrate/20251215205270_prepare_user_agent_details_organization_id_not_null_validation.rb new file mode 100644 index 0000000000000000000000000000000000000000..44b79d4dcc0e98ac5593aa9fe069b74aeb33c290 --- /dev/null +++ b/db/post_migrate/20251215205270_prepare_user_agent_details_organization_id_not_null_validation.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class PrepareUserAgentDetailsOrganizationIdNotNullValidation < Gitlab::Database::Migration[2.3] + milestone '18.9' + CONSTRAINT_NAME = 'check_17a3a18e31' + + def up + prepare_async_check_constraint_validation :user_agent_details, name: CONSTRAINT_NAME + end + + def down + unprepare_async_check_constraint_validation :user_agent_details, name: CONSTRAINT_NAME + end +end diff --git a/db/schema_migrations/20251215205262 b/db/schema_migrations/20251215205262 new file mode 100644 index 0000000000000000000000000000000000000000..bcbc132ec067e5c369fae7bde42bb76df580a708 --- /dev/null +++ b/db/schema_migrations/20251215205262 @@ -0,0 +1 @@ +c46c4671c35684946e97275a11ee645a7d0aa29ca00421430b83232e931d21a1 \ No newline at end of file diff --git a/db/schema_migrations/20251215205265 b/db/schema_migrations/20251215205265 new file mode 100644 index 0000000000000000000000000000000000000000..19678bffe6d65548cfeea9fe85d6e9bf14fec797 --- /dev/null +++ b/db/schema_migrations/20251215205265 @@ -0,0 +1 @@ +630bb6fd777f150d726835b50a5ba12882e5222646e9d0bcb817d301457811b8 \ No newline at end of file diff --git a/db/schema_migrations/20251215205270 b/db/schema_migrations/20251215205270 new file mode 100644 index 0000000000000000000000000000000000000000..544e7d6700616418346da8da7b7033cbf637dde5 --- /dev/null +++ b/db/schema_migrations/20251215205270 @@ -0,0 +1 @@ +36a103f7975527b41fb3d6b92a531d9f1caf5b2ccca75a61f1dff59fe132c711 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index df4c50822b7291d56b0616981711c011dad18d47..3dfd5fb64a48498055adabfad89b7707dabd77fb 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -35047,6 +35047,9 @@ ALTER TABLE epic_issues ALTER TABLE bulk_import_batch_trackers ADD CONSTRAINT check_13004cd9a8 CHECK ((num_nonnulls(namespace_id, organization_id, project_id) = 1)) NOT VALID; +ALTER TABLE user_agent_details + ADD CONSTRAINT check_17a3a18e31 CHECK ((organization_id IS NOT NULL)) NOT VALID; + ALTER TABLE workspaces ADD CONSTRAINT check_2a89035b04 CHECK ((personal_access_token_id IS NOT NULL)) NOT VALID; diff --git a/spec/services/spam/akismet_mark_as_spam_service_spec.rb b/spec/services/spam/akismet_mark_as_spam_service_spec.rb index aec80227829bac136443e1f4f56813ea0ba1f071..f07fa8d262b8358fff720d82f0939aac9b5f6cbd 100644 --- a/spec/services/spam/akismet_mark_as_spam_service_spec.rb +++ b/spec/services/spam/akismet_mark_as_spam_service_spec.rb @@ -40,12 +40,6 @@ subject.execute end - context 'when an organization is not assigned to the record' do - let(:user_agent_detail) { build(:user_agent_detail, organization: nil) } - - it { expect(subject.execute).to be_truthy } - end - context 'when Akismet does not consider it spam' do it 'does not update the spammable object as spam' do allow(fake_akismet_service).to receive(:submit_spam).and_return false