lenticular_cloud2/lenticular_cloud/migrations/versions/ff2f2e871dfc_init.py

75 lines
2.4 KiB
Python
Raw Normal View History

2022-02-20 15:58:04 +00:00
"""init
Revision ID: ff2f2e871dfc
Revises:
Create Date: 2022-02-20 16:56:13.258209
"""
from alembic import op
import sqlalchemy as sa
2022-04-08 19:28:22 +00:00
from sqlalchemy import engine_from_config
from sqlalchemy.engine import reflection
2022-02-20 15:58:04 +00:00
# revision identifiers, used by Alembic.
revision = 'ff2f2e871dfc'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
2022-04-08 19:28:22 +00:00
# init sate, migrate from non versioned db schema
# by checking if tables exist
config = op.get_context().config
engine = engine_from_config(
config.get_section(config.config_ini_section), prefix="sqlalchemy."
2022-02-20 15:58:04 +00:00
)
2022-04-08 19:28:22 +00:00
inspector = reflection.Inspector.from_engine(engine)
tables = inspector.get_table_names()
if 'user' not in tables:
op.create_table('user',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('alternative_email', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('modified_at', sa.DateTime(), nullable=False),
sa.Column('last_login', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('username')
)
if 'user_sign_up' not in tables:
op.create_table('user_sign_up',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('password', sa.String(), nullable=False),
sa.Column('alternative_email', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
if 'totp' not in tables:
op.create_table('totp',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('secret', sa.String(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('user_id', sa.String(length=36), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
2022-02-20 15:58:04 +00:00
# ### end Alembic commands ###
def downgrade():
2022-04-08 19:28:22 +00:00
pass
2022-02-20 15:58:04 +00:00
# ### commands auto generated by Alembic - please adjust! ###
2022-04-08 19:28:22 +00:00
#op.drop_table('totp')
#op.drop_table('user_sign_up')
#op.drop_table('user')
2022-02-20 15:58:04 +00:00
# ### end Alembic commands ###