Skip to content

Commit

Permalink
🗃️ DB migrations for new sample table
Browse files Browse the repository at this point in the history
  • Loading branch information
znatty22 committed Feb 12, 2024
1 parent 57fcd3c commit 24c56b2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions migrations/versions/1558052490ff_add_sample_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
1.17.0 Add new Sample table
Represents parent specimens of current Biospecimens
Revision ID: 1558052490ff
Revises: 3b427603af51
Create Date: 2024-02-02 10:13:44.030498
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from dataservice.api.common.model import KfId

# revision identifiers, used by Alembic.
revision = '1558052490ff'
down_revision = '3b427603af51'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('sample',
sa.Column('uuid', postgresql.UUID(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('modified_at', sa.DateTime(), nullable=True),
sa.Column('visible', sa.Boolean(),
server_default='true', nullable=False),
sa.Column('visibility_reason', sa.Text(), nullable=True),
sa.Column('visibility_comment', sa.Text(), nullable=True),
sa.Column('external_id', sa.Text(), nullable=True),
sa.Column('age_at_event_days',
sa.Integer(), nullable=True),
sa.Column('sample_event_key', sa.Text(), nullable=True),
sa.Column('tissue_type', sa.Text(), nullable=True),
sa.Column('sample_type', sa.Text(), nullable=True),
sa.Column('anatomical_location', sa.Text(), nullable=True),
sa.Column('volume_ul', sa.Float(), nullable=True),
sa.Column('method_of_sample_procurement',
sa.Text(), nullable=True),
sa.Column('preservation_method', sa.Text(), nullable=True),
sa.Column('participant_id', KfId(
length=11), nullable=False),
sa.Column('kf_id', KfId(
length=11), nullable=False),
sa.ForeignKeyConstraint(['participant_id'], [
'participant.kf_id'], ),
sa.PrimaryKeyConstraint('kf_id'),
sa.UniqueConstraint('external_id', 'participant_id', 'age_at_event_days', 'sample_type', 'anatomical_location',
'method_of_sample_procurement', 'tissue_type', 'preservation_method', name='sample_unique_constraint'),
sa.UniqueConstraint('uuid')
)
op.create_index(op.f('ix_sample_created_at'),
'sample', ['created_at'], unique=False)
op.add_column('biospecimen', sa.Column(
'sample_id', KfId(length=11), nullable=True))
op.create_foreign_key(None, 'biospecimen', 'sample',
['sample_id'], ['kf_id'])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'biospecimen', type_='foreignkey')
op.drop_column('biospecimen', 'sample_id')
op.drop_index(op.f('ix_sample_created_at'), table_name='sample')
op.drop_table('sample')
# ### end Alembic commands ###

0 comments on commit 24c56b2

Please sign in to comment.