university-final-iot-backend/migrations/versions/eeb3e64b76c4_.py

53 lines
1.6 KiB
Python
Raw Normal View History

2018-05-03 07:48:24 +00:00
"""empty message
2018-05-03 14:40:30 +00:00
Revision ID: eeb3e64b76c4
Revises: d1db8dcc190d
Create Date: 2018-05-03 16:24:30.369255
2018-05-03 07:48:24 +00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
2018-05-03 14:40:30 +00:00
revision = 'eeb3e64b76c4'
down_revision = 'd1db8dcc190d'
2018-05-03 07:48:24 +00:00
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
2018-05-03 14:40:30 +00:00
roles_table = op.create_table('roles',
2018-05-03 07:48:24 +00:00
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('display_name', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
2018-05-03 14:40:30 +00:00
accounts_table = op.create_table('accounts',
2018-05-03 07:48:24 +00:00
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=True),
sa.Column('password', sa.String(), nullable=True),
2018-05-03 14:40:30 +00:00
sa.Column('emails', sa.String(), nullable=True),
2018-05-03 07:48:24 +00:00
sa.Column('role_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
sa.PrimaryKeyConstraint('id')
)
2018-05-03 14:40:30 +00:00
op.create_index(op.f('ix_accounts_emails'), 'accounts', ['emails'], unique=True)
op.create_index(op.f('ix_accounts_username'), 'accounts', ['username'], unique=True)
op.bulk_insert(roles_table,
[
{'id':1, 'display_name':'ADMIN'},
{'id':2, 'display_name':'USER'}
]
)
2018-05-03 07:48:24 +00:00
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
2018-05-03 14:40:30 +00:00
op.drop_index(op.f('ix_accounts_username'), table_name='accounts')
op.drop_index(op.f('ix_accounts_emails'), table_name='accounts')
2018-05-03 07:48:24 +00:00
op.drop_table('accounts')
op.drop_table('roles')
# ### end Alembic commands ###