-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(backend): move revocation versionComment from dedicated column to metadata #6198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
theosanderson-agent
wants to merge
3
commits into
main
Choose a base branch
from
refactor/version-comment-to-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
backend/src/main/resources/db/migration/V1.26__move_version_comment_to_metadata.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| -- Moves revocation versionComment from the dedicated version_comment column | ||
| -- into the original_data JSONB metadata, and updates the view to automatically | ||
| -- construct joint_metadata for revocations from original_data. | ||
| -- This unifies how versionComment is stored for both revisions and revocations. | ||
|
|
||
| -- Step 1: For existing revocations with non-null version_comment and no original_data, | ||
| -- create original_data with versionComment in metadata | ||
| UPDATE sequence_entries | ||
| SET original_data = jsonb_build_object( | ||
| 'metadata', jsonb_build_object('versionComment', version_comment), | ||
| 'unalignedNucleotideSequences', '{}'::jsonb | ||
| ) | ||
| WHERE is_revocation = true AND version_comment IS NOT NULL AND original_data IS NULL; | ||
|
|
||
| -- For revocations that already have original_data (unlikely but safe), | ||
| -- merge versionComment into existing metadata | ||
| UPDATE sequence_entries | ||
| SET original_data = jsonb_set( | ||
| original_data, | ||
| '{metadata}', | ||
| COALESCE(original_data -> 'metadata', '{}'::jsonb) || jsonb_build_object('versionComment', version_comment) | ||
| ) | ||
| WHERE is_revocation = true AND version_comment IS NOT NULL AND original_data IS NOT NULL; | ||
|
|
||
| -- Step 2: Drop the view (must be done before dropping the column) | ||
| DROP VIEW IF EXISTS sequence_entries_view; | ||
|
|
||
| -- Step 3: Drop the version_comment column | ||
| ALTER TABLE sequence_entries DROP COLUMN version_comment; | ||
|
|
||
| -- Step 4: Recreate the view without version_comment. | ||
| -- For revocations, joint_metadata is constructed from original_data | ||
| -- so versionComment survives pipeline version changes. | ||
| CREATE VIEW sequence_entries_view AS | ||
| SELECT | ||
| se.accession, | ||
| se.version, | ||
| se.organism, | ||
| se.submission_id, | ||
| se.submitter, | ||
| se.approver, | ||
| se.group_id, | ||
| se.submitted_at, | ||
| se.released_at, | ||
| se.is_revocation, | ||
| se.original_data, | ||
| sepd.started_processing_at, | ||
| sepd.finished_processing_at, | ||
| sepd.processed_data, | ||
| CASE | ||
| WHEN se.is_revocation AND se.original_data IS NOT NULL THEN | ||
| jsonb_build_object( | ||
| 'metadata', COALESCE(se.original_data -> 'metadata', '{}'::jsonb), | ||
| 'unalignedNucleotideSequences', '{}'::jsonb, | ||
| 'alignedNucleotideSequences', '{}'::jsonb, | ||
| 'nucleotideInsertions', '{}'::jsonb, | ||
| 'alignedAminoAcidSequences', '{}'::jsonb, | ||
| 'aminoAcidInsertions', '{}'::jsonb, | ||
| 'files', 'null'::jsonb | ||
| ) | ||
| WHEN se.is_revocation THEN NULL | ||
| WHEN aem.external_metadata IS NULL THEN sepd.processed_data | ||
| ELSE sepd.processed_data || | ||
| jsonb_build_object('metadata', (sepd.processed_data -> 'metadata') || aem.external_metadata) | ||
| END AS joint_metadata, | ||
| CASE | ||
| WHEN se.is_revocation THEN cpp.version | ||
| ELSE sepd.pipeline_version | ||
| END AS pipeline_version, | ||
| sepd.errors, | ||
| sepd.warnings, | ||
| CASE | ||
| WHEN se.released_at IS NOT NULL THEN 'APPROVED_FOR_RELEASE' | ||
| WHEN se.is_revocation THEN 'PROCESSED' | ||
| WHEN sepd.processing_status = 'IN_PROCESSING' THEN 'IN_PROCESSING' | ||
| WHEN sepd.processing_status = 'PROCESSED' THEN 'PROCESSED' | ||
| ELSE 'RECEIVED' | ||
| END AS status, | ||
| CASE | ||
| WHEN sepd.processing_status = 'IN_PROCESSING' THEN NULL | ||
| WHEN sepd.errors IS NOT NULL AND jsonb_array_length(sepd.errors) > 0 THEN 'HAS_ERRORS' | ||
| WHEN sepd.warnings IS NOT NULL AND jsonb_array_length(sepd.warnings) > 0 THEN 'HAS_WARNINGS' | ||
| ELSE 'NO_ISSUES' | ||
| END AS processing_result | ||
| FROM sequence_entries se | ||
| LEFT JOIN current_processing_pipeline cpp | ||
| ON se.organism = cpp.organism | ||
| LEFT JOIN sequence_entries_preprocessed_data sepd | ||
| ON se.accession = sepd.accession | ||
| AND se.version = sepd.version | ||
| AND sepd.pipeline_version = cpp.version | ||
| LEFT JOIN ( | ||
| SELECT | ||
| em.accession, | ||
| em.version, | ||
| jsonb_merge_agg(em.external_metadata) AS external_metadata | ||
| FROM external_metadata em | ||
| GROUP BY em.accession, em.version | ||
| ) aem | ||
| ON aem.accession = se.accession | ||
| AND aem.version = se.version; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the dedicated revocation
versionCommentmerge here makes the value depend entirely onprocessedData.metadata, but that path is normalized byProcessedMetadataPostprocessor.filterOutExtraFieldsAndAddNulls, which drops metadata keys not present in the organism schema. In environments/configs whereversionCommentis not part of schema metadata (for example the backend test configs), revocation comments will silently disappear from released data after this change. Previously this code guaranteed the field by injecting it after postprocessing.Useful? React with 👍 / 👎.