Skip to content

Commit

Permalink
progress in fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Jan 23, 2025
1 parent fea3e3a commit 19959ca
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.loculus.backend.service.debug

import org.jetbrains.exposed.sql.deleteAll
import org.jetbrains.exposed.sql.insert
import org.loculus.backend.config.BackendConfig
import org.loculus.backend.service.datauseterms.DataUseTermsTable
import org.loculus.backend.service.submission.CurrentProcessingPipelineTable
import org.loculus.backend.service.submission.MetadataUploadAuxTable
Expand All @@ -13,7 +14,7 @@ import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

@Component
class DeleteSequenceDataService(private val dateProvider: DateProvider) {
class DeleteSequenceDataService(private val dateProvider: DateProvider, private val config: BackendConfig) {
@Transactional
fun deleteAllSequenceData() {
SequenceEntriesTable.deleteAll()
Expand All @@ -22,9 +23,6 @@ class DeleteSequenceDataService(private val dateProvider: DateProvider) {
SequenceUploadAuxTable.deleteAll()
DataUseTermsTable.deleteAll()
CurrentProcessingPipelineTable.deleteAll()
CurrentProcessingPipelineTable.insert {
it[versionColumn] = 1
it[startedUsingAtColumn] = dateProvider.getCurrentDateTime()
}
CurrentProcessingPipelineTable.setV1ForOrganismsIfNotExist(config.organisms.keys, dateProvider.getCurrentDateTime())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,71 @@ DROP CONSTRAINT current_processing_pipeline_pkey;
ALTER TABLE current_processing_pipeline
ADD CONSTRAINT current_processing_pipeline_pkey PRIMARY KEY (organism, version);




drop view if exists external_metadata_view cascade;

create view external_metadata_view as
select
cpd.accession,
cpd.version,
all_external_metadata.updated_metadata_at,
-- Combines metadata from preprocessed data with any external metadata updates
-- If there's no external metadata, just use the preprocessed data's metadata
-- If there is external metadata, merge it with preprocessed data (external takes precedence)
case
when all_external_metadata.external_metadata is null then
jsonb_build_object('metadata', (cpd.processed_data->'metadata'))
else
jsonb_build_object(
'metadata',
(cpd.processed_data->'metadata') || all_external_metadata.external_metadata
)
end as joint_metadata
from
(
-- Get only the preprocessed data for the current pipeline version
select * from sequence_entries_preprocessed_data
where pipeline_version = (select version from current_processing_pipeline
where organism = (
select organism from sequence_entries se
where se.accession = sequence_entries_preprocessed_data.accession
and se.version = sequence_entries_preprocessed_data.version
))
) cpd
left join all_external_metadata on
all_external_metadata.accession = cpd.accession
and all_external_metadata.version = cpd.version;

create view sequence_entries_view as
select
se.*,
sepd.started_processing_at,
sepd.finished_processing_at,
sepd.processed_data as processed_data,
sepd.processed_data || em.joint_metadata as joint_metadata,
sepd.errors,
sepd.warnings,
case
when se.released_at is not null then 'APPROVED_FOR_RELEASE'
when se.is_revocation then 'AWAITING_APPROVAL'
when sepd.processing_status = 'IN_PROCESSING' then 'IN_PROCESSING'
when sepd.processing_status = 'HAS_ERRORS' then 'HAS_ERRORS'
when sepd.processing_status = 'FINISHED' then 'AWAITING_APPROVAL'
else 'RECEIVED'
end as status
from
sequence_entries se
left join sequence_entries_preprocessed_data sepd on
se.accession = sepd.accession
and se.version = sepd.version
and sepd.pipeline_version = (select version from current_processing_pipeline
where organism = (
select organism from sequence_entries se
where se.accession = sepd.accession
and se.version = sepd.version
))
left join external_metadata_view em on
se.accession = em.accession
and se.version = em.version;
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ private fun clearDatabaseStatement(): String = """
$USER_GROUPS_TABLE_NAME,
$METADATA_UPLOAD_AUX_TABLE_NAME,
$SEQUENCE_UPLOAD_AUX_TABLE_NAME,
$DATA_USE_TERMS_TABLE_NAME
$DATA_USE_TERMS_TABLE_NAME,
$CURRENT_PROCESSING_PIPELINE_TABLE_NAME
cascade;
alter sequence $ACCESSION_SEQUENCE_NAME restart with 1;
update $CURRENT_PROCESSING_PIPELINE_TABLE_NAME set version = 1, started_using_at = now();
insert into $CURRENT_PROCESSING_PIPELINE_TABLE_NAME values
(1, now(), '$DEFAULT_ORGANISM'),
(1, now(), '$OTHER_ORGANISM'),
(1, now(), '$ORGANISM_WITHOUT_CONSENSUS_SEQUENCES');
"""

0 comments on commit 19959ca

Please sign in to comment.