From bc609effe68d730528b095bf03745c83872d6732 Mon Sep 17 00:00:00 2001 From: Shane Giles Date: Thu, 4 Apr 2024 18:41:31 -0600 Subject: [PATCH] feat(IPVC-2323): update data type for assocacs added field --- ...ae896_add_sqlalchemy_model_for_assocacs.py | 44 +++++++++++++++++++ .../versions/edadb97f6502_initial_state.py | 3 +- src/uta/models.py | 3 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/alembic/versions/cc51f50ae896_add_sqlalchemy_model_for_assocacs.py diff --git a/src/alembic/versions/cc51f50ae896_add_sqlalchemy_model_for_assocacs.py b/src/alembic/versions/cc51f50ae896_add_sqlalchemy_model_for_assocacs.py new file mode 100644 index 0000000..c8ee756 --- /dev/null +++ b/src/alembic/versions/cc51f50ae896_add_sqlalchemy_model_for_assocacs.py @@ -0,0 +1,44 @@ +"""add sqlalchemy model for assocacs + +Revision ID: cc51f50ae896 +Revises: edadb97f6502 +Create Date: 2024-04-05 00:33:40.105587 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'cc51f50ae896' +down_revision: Union[str, None] = 'edadb97f6502' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('associated_accessions', 'tx_ac', + existing_type=sa.TEXT(), + nullable=False, + schema='uta') + op.alter_column('associated_accessions', 'pro_ac', + existing_type=sa.TEXT(), + nullable=False, + schema='uta') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('associated_accessions', 'pro_ac', + existing_type=sa.TEXT(), + nullable=True, + schema='uta') + op.alter_column('associated_accessions', 'tx_ac', + existing_type=sa.TEXT(), + nullable=True, + schema='uta') + # ### end Alembic commands ### diff --git a/src/alembic/versions/edadb97f6502_initial_state.py b/src/alembic/versions/edadb97f6502_initial_state.py index 064713f..86ea9cd 100644 --- a/src/alembic/versions/edadb97f6502_initial_state.py +++ b/src/alembic/versions/edadb97f6502_initial_state.py @@ -9,6 +9,7 @@ from alembic import op import sqlalchemy as sa +from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. @@ -134,7 +135,7 @@ def upgrade() -> None: sa.Column('tx_ac', sa.Text(), nullable=True), sa.Column('pro_ac', sa.Text(), nullable=True), sa.Column('origin', sa.Text(), nullable=False), - sa.Column('added', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False), + sa.Column('added', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False), sa.PrimaryKeyConstraint('associated_accession_id'), schema='uta' ) diff --git a/src/uta/models.py b/src/uta/models.py index 6292c97..9a598b1 100644 --- a/src/uta/models.py +++ b/src/uta/models.py @@ -9,6 +9,7 @@ import sqlalchemy.types import sqlalchemy.sql.functions from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.dialects import postgresql ############################################################################ @@ -235,7 +236,7 @@ class AssociatedAccessions(Base): pro_ac = sa.Column(sa.Text, nullable=False) origin = sa.Column(sa.Text, nullable=False) added = sa.Column( - sqlalchemy.types.TIMESTAMP, + postgresql.TIMESTAMP(timezone=True), server_default=sqlalchemy.sql.functions.now(), nullable=False, )