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:
-
Require a
sharding_key_issue_urlif adesired_sharding_keyis present. This ensures all ongoing sharding work is tracked by a valid issue. -
Forbid a
sharding_key_issue_urlif a finalsharding_keyis present (cleanup). - 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
- Related to #580964 (closed)
Screenshots or screen recordings
N/A - Backend test change only.
| Before | After |
|---|---|
How to set up and validate locally
-
Verify the specs pass with the current allowlist:
bin/rspec spec/lib/gitlab/database/sharding_key_spec.rb -
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_idbut do not add asharding_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.
- Pick a random table definition in
-
Verify the allowlist enforcement (Cleanup scenario):
- Pick a table currently in the new allowlist (e.g.,
spam_logs). - Edit
db/docs/spam_logs.ymland add a validsharding_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.
- Pick a table currently in the new allowlist (e.g.,
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.