-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ DB migrations for new sample table
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ### |