initial commit
This commit is contained in:
1
alembic/README
Normal file
1
alembic/README
Normal file
@@ -0,0 +1 @@
|
||||
Generic single-database configuration.
|
||||
85
alembic/env.py
Normal file
85
alembic/env.py
Normal file
@@ -0,0 +1,85 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
import sys
|
||||
from pathlib import Path
|
||||
sys.path.append(Path(__file__).parents[1].joinpath("src").resolve().__str__())
|
||||
print(sys.path)
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
from submissions.backend.db.models import Base
|
||||
target_metadata = [Base.metadata]
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL
|
||||
and not an Engine, though an Engine is acceptable
|
||||
here as well. By skipping the Engine creation
|
||||
we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
# must be set to true for sqlite workaround
|
||||
render_as_batch=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata,
|
||||
render_as_batch=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
24
alembic/script.py.mako
Normal file
24
alembic/script.py.mako
Normal file
@@ -0,0 +1,24 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
155
alembic/versions/4cba0c1ffe03_initial_commit.py
Normal file
155
alembic/versions/4cba0c1ffe03_initial_commit.py
Normal file
@@ -0,0 +1,155 @@
|
||||
"""initial commit
|
||||
|
||||
Revision ID: 4cba0c1ffe03
|
||||
Revises:
|
||||
Create Date: 2023-01-18 08:59:34.382715
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4cba0c1ffe03'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('_contacts',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.Column('email', sa.String(length=64), nullable=True),
|
||||
sa.Column('phone', sa.String(length=32), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('_control_types',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('targets', sa.JSON(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_table('_kits',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.Column('used_for', sa.JSON(), nullable=True),
|
||||
sa.Column('cost_per_run', sa.FLOAT(precision=2), nullable=True),
|
||||
sa.Column('reagent_types_id', sa.INTEGER(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['reagent_types_id'], ['_reagent_types.id'], name='fk_KT_reagentstype_id', ondelete='SET NULL', use_alter=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_table('_reagent_types',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.Column('kit_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('eol_ext', sa.Interval(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['kit_id'], ['_kits.id'], name='fk_RT_kits_id', ondelete='SET NULL', use_alter=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('_ww_samples',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('ww_processing_num', sa.String(length=64), nullable=True),
|
||||
sa.Column('ww_sample_full_id', sa.String(length=64), nullable=True),
|
||||
sa.Column('rsl_number', sa.String(length=64), nullable=True),
|
||||
sa.Column('collection_date', sa.TIMESTAMP(), nullable=True),
|
||||
sa.Column('testing_type', sa.String(length=64), nullable=True),
|
||||
sa.Column('site_status', sa.String(length=64), nullable=True),
|
||||
sa.Column('notes', sa.String(length=2000), nullable=True),
|
||||
sa.Column('ct_n1', sa.FLOAT(precision=2), nullable=True),
|
||||
sa.Column('ct_n2', sa.FLOAT(precision=2), nullable=True),
|
||||
sa.Column('seq_submitted', sa.BOOLEAN(), nullable=True),
|
||||
sa.Column('ww_seq_run_id', sa.String(length=64), nullable=True),
|
||||
sa.Column('sample_type', sa.String(length=8), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('_control_samples',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('parent_id', sa.String(), nullable=True),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('submitted_date', sa.TIMESTAMP(), nullable=True),
|
||||
sa.Column('contains', sa.JSON(), nullable=True),
|
||||
sa.Column('matches', sa.JSON(), nullable=True),
|
||||
sa.Column('kraken', sa.JSON(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['parent_id'], ['_control_types.id'], name='fk_control_parent_id'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_table('_organizations',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.Column('cost_centre', sa.String(), nullable=True),
|
||||
sa.Column('contact_ids', sa.INTEGER(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['contact_ids'], ['_contacts.id'], name='fk_org_contact_id', ondelete='SET NULL'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('_reagents',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('type_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.Column('lot', sa.String(length=64), nullable=True),
|
||||
sa.Column('expiry', sa.TIMESTAMP(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['type_id'], ['_reagent_types.id'], name='fk_reagent_type_id', ondelete='SET NULL'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('_reagentstypes_kittypes',
|
||||
sa.Column('reagent_types_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('kits_id', sa.INTEGER(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['kits_id'], ['_kits.id'], ),
|
||||
sa.ForeignKeyConstraint(['reagent_types_id'], ['_reagent_types.id'], )
|
||||
)
|
||||
op.create_table('_orgs_contacts',
|
||||
sa.Column('org_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('contact_id', sa.INTEGER(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['contact_id'], ['_contacts.id'], ),
|
||||
sa.ForeignKeyConstraint(['org_id'], ['_organizations.id'], )
|
||||
)
|
||||
op.create_table('_submissions',
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('rsl_plate_num', sa.String(length=32), nullable=True),
|
||||
sa.Column('submitter_plate_num', sa.String(length=127), nullable=True),
|
||||
sa.Column('submitted_date', sa.TIMESTAMP(), nullable=True),
|
||||
sa.Column('submitting_lab_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('sample_count', sa.INTEGER(), nullable=True),
|
||||
sa.Column('extraction_kit_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('submission_type', sa.String(length=32), nullable=True),
|
||||
sa.Column('technician', sa.String(length=64), nullable=True),
|
||||
sa.Column('reagents_id', sa.String(), nullable=True),
|
||||
sa.Column('control_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('sample_id', sa.String(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['control_id'], ['_control_samples.id'], name='fk_BC_control_id', ondelete='SET NULL'),
|
||||
sa.ForeignKeyConstraint(['extraction_kit_id'], ['_kits.id'], ondelete='SET NULL'),
|
||||
sa.ForeignKeyConstraint(['reagents_id'], ['_reagents.id'], name='fk_BS_reagents_id', ondelete='SET NULL'),
|
||||
sa.ForeignKeyConstraint(['sample_id'], ['_ww_samples.id'], name='fk_WW_sample_id', ondelete='SET NULL'),
|
||||
sa.ForeignKeyConstraint(['submitting_lab_id'], ['_organizations.id'], ondelete='SET NULL'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('rsl_plate_num'),
|
||||
sa.UniqueConstraint('submitter_plate_num')
|
||||
)
|
||||
op.create_table('_reagents_submissions',
|
||||
sa.Column('reagent_id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('submission_id', sa.INTEGER(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['reagent_id'], ['_reagents.id'], ),
|
||||
sa.ForeignKeyConstraint(['submission_id'], ['_submissions.id'], )
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('_reagents_submissions')
|
||||
op.drop_table('_submissions')
|
||||
op.drop_table('_orgs_contacts')
|
||||
op.drop_table('_reagentstypes_kittypes')
|
||||
op.drop_table('_reagents')
|
||||
op.drop_table('_organizations')
|
||||
op.drop_table('_control_samples')
|
||||
op.drop_table('_ww_samples')
|
||||
op.drop_table('_reagent_types')
|
||||
op.drop_table('_kits')
|
||||
op.drop_table('_control_types')
|
||||
op.drop_table('_contacts')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user