Skip to content
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

feat(IPVC-2280): add codon_table to transcript + migration #21

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
30 changes: 30 additions & 0 deletions src/alembic/versions/a697b584f699_add_codon_table_to_transcript.py
Original file line number Diff line number Diff line change
@@ -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 ###
1 change: 1 addition & 0 deletions src/uta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading