Skip to content

Snippet Repos loose foreign keys

The following discussion from !207525 should be addressed:

Found extra cross-database foreign key snippet_repositories.shard_id referencing shards with constraint name fk_rails_f21f899728

This failure in https://gitlab.com/gitlab-org/gitlab/-/jobs/11624602377 is because "normal" foreign keys are only allowed between tables within the same schema. (When an organization's PG data is moved from one cell to another, the snippet_repositories.shard_id will be nullified, to be set with a new shard_id that is applicable to the new cell.) This is why we must first do this:

  1. Replace shard_id FK with LFK (loose foreign key)

Found extra cross-database foreign key snippet_repository_states.snippet_repository_id referencing snippet_repositories with constraint name fk_5f750f3182.

This failure is similar, and the resolution is similar to, we just need to replace the snippet_repository_id FK with a LFK before this MR.

 1.3) Failure/Error:
        expect(allowlist).to be_empty, "The following items must be allowed_cross_database_foreign_keys` list," \
          "as it no longer appears as cross-database foreign key:\n" \
          "#{formatted_allowlist}"
        The following items must be allowed_cross_database_foreign_keys` list,as it no longer appears as cross-database foreign key:
        - snippet_repositories.snippet_id
        - snippet_repositories.snippet_organization_id
        - snippet_repositories.snippet_project_id

I think this is saying to remove lines from the allowed_cross_database_foreign_keys let variable.

Edited by Hunter Stewart