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_forto all existing Geo verifiable models (20 models total) through existing shared examples - Cleans up the
project_repositoryfactory by removing redundant trait definitions - Adds an override to the default
.create_verification_details_formethod forProjectRepositoryto 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
- Querying 1000 (max batch) records with ids from 1 to 1000: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/48825/commands/146252
INSERT statement
- Inserting 1000 (max batch) records with (1,1) to (1000,1000) pairs: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/48825/commands/146251
- Inserting 1000 records based on real values (
INSERTbased on aSELECT): https://postgres.ai/console/gitlab/gitlab-production-main/sessions/48825/commands/146248.⚠️ This is not the exact plan as I can't find 1000id, project_idpairs that actually do exist in the database.
References
- addressed #590457 (closed)
- related to #590033 (closed)
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.