diff --git a/README.md b/README.md index 78da019..84e606c 100644 --- a/README.md +++ b/README.md @@ -342,3 +342,18 @@ Example: ``` sbin/uta-update $(pwd)/ncbi-data $(pwd)/seqrepo-data $(pwd)/uta-build uta_20210129b 2024-02-20 ``` + +## Migrations +UTA uses alembic to manage database migrations. To auto-generate a migration: +``` +alembic -c etc/alembic.ini revision --autogenerate -m "description of the migration" +``` +This will create a migration script in the alembic/versions directory. +Adjust the upgrade and downgrade function definitions. To apply the migration: +``` +alembic -c etc/alembic.ini upgrade head +``` +To reverse a migration, use `downgrade` with the number of steps to reverse. For example, to reverse the last: +``` +alembic -c etc/alembic.ini downgrade -1 +``` diff --git a/src/alembic/versions/a697b584f699_add_codon_table_to_transcript.py b/src/alembic/versions/a697b584f699_add_codon_table_to_transcript.py new file mode 100644 index 0000000..cb6eec1 --- /dev/null +++ b/src/alembic/versions/a697b584f699_add_codon_table_to_transcript.py @@ -0,0 +1,30 @@ +"""add codon_table to Transcript + +Revision ID: a697b584f699 +Revises: cc51f50ae896 +Create Date: 2024-04-08 17:27:41.570024 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'a697b584f699' +down_revision: Union[str, None] = 'cc51f50ae896' +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.add_column('transcript', sa.Column('codon_table', sa.Integer(), server_default='1', nullable=False), schema='uta') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('transcript', 'codon_table', schema='uta') + # ### end Alembic commands ### diff --git a/src/uta/models.py b/src/uta/models.py index 9a598b1..31a5392 100644 --- a/src/uta/models.py +++ b/src/uta/models.py @@ -130,6 +130,7 @@ class Transcript(Base): cds_md5 = sa.Column(sa.Text, index=True) added = sa.Column( sa.DateTime, default=datetime.datetime.now(), nullable=False) + codon_table = sa.Column(sa.Integer, nullable=False, server_default='1') # 1 = standard, 2 = mitochondrial # relationships: origin = sao.relationship("Origin", backref="transcripts")