Geo: Add test case for .create_verification_details_for in verifiable models

What does this MR do and why?

This MR adds test coverage to ensure that the Geo::VerificationStateBackfillService and the .create_verification_details_for method do not create duplicate verification records for existing Geo models.

This is important because .create_verification_details_for uses Rails' insert_all, which bypasses Rails validations and relies on database constraints.

Changes:

  • Adds duplication tests for.create_verification_details_for to all existing Geo verifiable models (20 models total) through existing shared examples
  • Cleans up the project_repository factory by removing redundant trait definitions
  • Adds an override to the default .create_verification_details_for method for ProjectRepository to ensure record creation and uniqueness as far as possible

This ensures all Geo models have proper test coverage to catch missing database constraints that would allow duplicate verification records.

Database plan

Code and queries

rows = primary_key_in(primary_keys.to_a - keys_with_existing_states).map do |project_repo|
          { verification_state_model_key => project_repo.id, :project_id => project_repo.project_id }
        end

verification_state_table_class.insert_all(rows)

where verification_state_table_class is ProjectRepositoryState.

This gives us the following queries, when the primary_keys is a range for 1..20 and records 1 to 10 already exist:

SELECT "project_repositories".* FROM "project_repositories" WHERE "project_repositories"."id" IN (11, 12, 13, 14, 15, 16, 17, 18, 19, 20)

first and then:

INSERT INTO "project_repository_states" ("project_repository_id","project_id") VALUES (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20) ON CONFLICT  DO NOTHING RETURNING "id"

The default batch size can be found in the VerifiableReplicator class and is defined at 1000.

Query plans

SELECT statement

INSERT statement

References

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Chloe Fons

Merge request reports

Loading
Loading