Enforce issue URL requirement for tables with desired_sharding_key

What does this MR do and why?

This MR updates the sharding_key_spec to enforce stricter validation regarding sharding key definitions in db/docs/.

Previously, the spec did not enforce that tables defining a desired_sharding_key (indicating work-in-progress) must also provide a sharding_key_issue_url.

This MR changes the validation logic to:

  1. Require a sharding_key_issue_url if a desired_sharding_key is present. This ensures all ongoing sharding work is tracked by a valid issue.
  2. Forbid a sharding_key_issue_url if a final sharding_key is present (cleanup).
  3. Introduce an allowlist (allowed_to_be_missing_sharding_key_issue_url) for existing tables that currently define a desired key but lack an issue URL. This prevents immediate spec failures while ensuring no new tables can be added without an issue link.

References

Screenshots or screen recordings

N/A - Backend test change only.

Before After

How to set up and validate locally

  1. Verify the specs pass with the current allowlist:

    bin/rspec spec/lib/gitlab/database/sharding_key_spec.rb
  2. Verify the new validation (Failure scenario):

    • Pick a random table definition in db/docs/ (e.g., db/docs/users.yml).
    • Add desired_sharding_key: project_id but do not add a sharding_key_issue_url.
    • Run the spec: bin/rspec spec/lib/gitlab/database/sharding_key_spec.rb
    • Expected Result: The test should fail asking for a URL.
  3. Verify the allowlist enforcement (Cleanup scenario):

    • Pick a table currently in the new allowlist (e.g., spam_logs).
    • Edit db/docs/spam_logs.yml and add a valid sharding_key_issue_url.
    • Run the spec: bin/rspec spec/lib/gitlab/database/sharding_key_spec.rb
    • Expected Result: The test should fail stating the table must be removed from the exemption list.

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.

Merge request reports

Loading