SQL: Prevent duplicate metadata_value for (submission_id, metadata_key) in submissions_metadata#139
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the SQLite schema to enforce the same invariant as the Rust-side StrategicMetadataMap: for each submission, there can be only one metadata_value per metadata_key in submissions_metadata.
Changes:
- Replaces the
submissions_metadataprimary key to be(submission_id, metadata_key)to prevent multiple values per key per submission. - Adds a data migration step that deterministically deduplicates legacy rows by keeping
MAX(metadata_value)per(submission_id, metadata_key). - Provides a down migration to restore the previous
(submission_id, metadata_key, metadata_value)primary key.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| opsqueue/migrations/20260717143000_submission_metadata_pk_by_key.up.sql | Rebuilds submissions_metadata with a PK on (submission_id, metadata_key) and dedupes legacy data. |
| opsqueue/migrations/20260717143000_submission_metadata_pk_by_key.down.sql | Rebuilds submissions_metadata back to the prior PK including metadata_value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jerbaroo
left a comment
There was a problem hiding this comment.
Yes this makes sense, nice change
|
@OpsBotPrime merge on Friday! |
|
Rebased as 6d7c612, waiting for CI … |
|
CI job 🟡 started. |
|
The build failed ❌. If this is the result of a flaky test, then tag me again with the |
|
@OpsBotPrime retry on Friday! |
…_key)` in `submissions_metadata` This brings the SQL schema inline with the code enforced `StrategicMetadataMap`.
…id, metadata_key)` in `submissions_metadata` Approved-by: ReinierMaas Priority: Normal Auto-deploy: false
|
Rebased as 4179873, waiting for CI … |
|
CI job 🟡 started. |
145595e to
4179873
Compare
This brings the SQL schema inline with the code enforced
StrategicMetadataMap.For each submission we are tracking one
metadata_valueper key. We don't allow multiplemetadata_valuesfor the same key to be specified on a single submission.