Some work with FastAPI and SQLAlchemy, including automated alembic migrations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.9 KiB

"""Adding users and items tables
Revision ID: 4fe3d42f09bc
Revises: b00a3ca977cc
Create Date: 2019-07-02 19:13:32.182089
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '4fe3d42f09bc'
down_revision = 'b00a3ca977cc'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('ix_users_email', table_name='users')
op.drop_index('ix_users_id', table_name='users')
op.drop_table('users')
op.drop_index('ix_items_description', table_name='items')
op.drop_index('ix_items_id', table_name='items')
op.drop_index('ix_items_title', table_name='items')
op.drop_table('items')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('items',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('title', sa.VARCHAR(), nullable=True),
sa.Column('description', sa.VARCHAR(), nullable=True),
sa.Column('owner_id', sa.INTEGER(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index('ix_items_title', 'items', ['title'], unique=False)
op.create_index('ix_items_id', 'items', ['id'], unique=False)
op.create_index('ix_items_description', 'items', ['description'], unique=False)
op.create_table('users',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('email', sa.VARCHAR(), nullable=True),
sa.Column('hashed_password', sa.VARCHAR(), nullable=True),
sa.Column('is_active', sa.BOOLEAN(), nullable=True),
sa.CheckConstraint('is_active IN (0, 1)'),
sa.PrimaryKeyConstraint('id')
)
op.create_index('ix_users_id', 'users', ['id'], unique=False)
op.create_index('ix_users_email', 'users', ['email'], unique=1)
# ### end Alembic commands ###