Skip to content

SQL: Prevent duplicate metadata_value for (submission_id, metadata_key) in submissions_metadata#139

Merged
OpsBotPrime merged 2 commits into
masterfrom
reinier/tighten-submissions-metadata
Jul 17, 2026
Merged

SQL: Prevent duplicate metadata_value for (submission_id, metadata_key) in submissions_metadata#139
OpsBotPrime merged 2 commits into
masterfrom
reinier/tighten-submissions-metadata

Conversation

@ReinierMaas

Copy link
Copy Markdown
Contributor

This brings the SQL schema inline with the code enforced StrategicMetadataMap.

For each submission we are tracking one metadata_value per key. We don't allow multiple metadata_values for the same key to be specified on a single submission.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_metadata primary 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 jerbaroo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this makes sense, nice change

@ReinierMaas

Copy link
Copy Markdown
Contributor Author

@OpsBotPrime merge on Friday!

@OpsBotPrime

Copy link
Copy Markdown
Contributor

Rebased as 6d7c612, waiting for CI …

@OpsBotPrime

Copy link
Copy Markdown
Contributor

CI job 🟡 started.

@OpsBotPrime

Copy link
Copy Markdown
Contributor

The build failed ❌.

If this is the result of a flaky test, then tag me again with the retry command. Otherwise, push a new commit and tag me again.

@ReinierMaas

Copy link
Copy Markdown
Contributor Author

@OpsBotPrime retry on Friday!

ReinierMaas and others added 2 commits July 17, 2026 17:14
…_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
@OpsBotPrime

Copy link
Copy Markdown
Contributor

Rebased as 4179873, waiting for CI …

@OpsBotPrime

Copy link
Copy Markdown
Contributor

CI job 🟡 started.

@OpsBotPrime
OpsBotPrime force-pushed the reinier/tighten-submissions-metadata branch from 145595e to 4179873 Compare July 17, 2026 15:20
@OpsBotPrime
OpsBotPrime merged commit 4179873 into master Jul 17, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants