Create project_repository records only when Git repositories exist
What does this MR do and why?
project_repository
records were being created for all projects, even those without Git repositories. This caused problems in Geo replication:
- Projects without repositories displayed "Project Repositories checksum failure" in the UI
- Secondary sites reported synchronization failures with "Error syncing repository: 13:creating repository: cloning repository: exit status 128"
- Primary sites reported "Repository does not exist" when attempting to checksum Git repositories
- This led to false error reporting, wasted sync attempts, and unclear Geo health assessments
Once, users switch to geo_project_repository_replication_v2, the project_repositories table will be enumerated instead of the projects table.
The solution ensures that project_repository
records are only created when Git repositories are created and associated with a project record.
- For new projects created through
Projects::CreateService
:
- If no repository exists (e.g., for projects that will only have issues/wiki), no
project_repository
record is created
- For existing projects and operations like update/transfer:
- The
in_transit
flag can ensureproject_repository
is created with even when therepository_exists?
check fails
Services Affected
The following services call track_project_repository
and will now automatically respect the new behavior:
-
Projects::CreateService
- Only creates records after successful repository creation -
Projects::AfterRenameService
- Updates existing projects (which should have repositories) -
Projects::TransferService
- Transfers existing projects -
Projects::UpdateRepositoryStorageService
- Moves existing repositories
The change also ensures that a project_repository
record is removed when a project's repository is deleted.
Database review information
One new query is introduced in app.models/project.rb in the method remove_repository
by the statement project_repository&.destroy
.
The SQL is DELETE FROM "project_repositories" WHERE "project_repositories"."id" = 4
The query plan can be found here https://explain.depesz.com/s/xMPp#html
Related issue: Geo: Insert a record in project_repositories on... (#546176)
References
Screenshots or screen recordings
Before | After |
---|---|
How to set up and validate locally
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.