diff --git a/nmdc_server/fakes.py b/nmdc_server/fakes.py index dab7f892..cfe95f33 100644 --- a/nmdc_server/fakes.py +++ b/nmdc_server/fakes.py @@ -396,7 +396,7 @@ class Meta: "facilities": [], "otherAward": "", }, - "packageName": "", + "packageName": [], } locked_by = None lock_updated = None diff --git a/nmdc_server/migrations/versions/afa1ff687968_convert_packagename_to_an_array.py b/nmdc_server/migrations/versions/afa1ff687968_convert_packagename_to_an_array.py new file mode 100644 index 00000000..3e574314 --- /dev/null +++ b/nmdc_server/migrations/versions/afa1ff687968_convert_packagename_to_an_array.py @@ -0,0 +1,57 @@ +"""Convert packageName to an array + +Revision ID: afa1ff687968 +Revises: 317274ad8137 +Create Date: 2024-08-28 22:27:28.622234 + +""" + +from typing import Optional + +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects.postgresql import JSONB +from sqlalchemy.sql import column, table + +# revision identifiers, used by Alembic. +revision: str = "afa1ff687968" +down_revision: Optional[str] = "317274ad8137" +branch_labels: Optional[str] = None +depends_on: Optional[str] = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + submission_metadata = table( + "submission_metadata", + column("id", sa.String), + column("metadata_submission", JSONB), + column("study_name", sa.String), + column("templates", JSONB), + ) + + connection = op.get_bind() + submissions = connection.execute( + sa.select([submission_metadata.c.id, submission_metadata.c.metadata_submission]) + ) + + for submission in submissions: + metadata_submission = submission.metadata_submission + package_name = metadata_submission.get("packageName") + + if isinstance(package_name, str): + metadata_submission["packageName"] = [package_name] + + update_stmt = ( + submission_metadata.update() + .where(submission_metadata.c.id == submission.id) + .values(metadata_submission=metadata_submission) + ) + connection.execute(update_stmt) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ### diff --git a/nmdc_server/schemas_submission.py b/nmdc_server/schemas_submission.py index 1aab2e70..d8f0836b 100644 --- a/nmdc_server/schemas_submission.py +++ b/nmdc_server/schemas_submission.py @@ -73,7 +73,7 @@ class ContextForm(BaseModel): class MetadataSubmissionRecord(BaseModel): - packageName: str + packageName: List[str] contextForm: ContextForm addressForm: AddressForm templates: List[str] @@ -83,7 +83,7 @@ class MetadataSubmissionRecord(BaseModel): class PartialMetadataSubmissionRecord(BaseModel): - packageName: Optional[str] + packageName: Optional[List[str]] contextForm: Optional[ContextForm] addressForm: Optional[AddressForm] templates: Optional[List[str]] diff --git a/web/src/views/SubmissionPortal/Components/TemplateChooser.vue b/web/src/views/SubmissionPortal/Components/TemplateChooser.vue index 80b86d1a..ea6a9cca 100644 --- a/web/src/views/SubmissionPortal/Components/TemplateChooser.vue +++ b/web/src/views/SubmissionPortal/Components/TemplateChooser.vue @@ -32,38 +32,39 @@ export default defineComponent({