"""First Commit

Revision ID: 9ff8b944e513
Revises: 
Create Date: 2021-05-05 15:25:23.578492

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9ff8b944e513'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("create schema fastapi")
    op.create_table('tag',
    sa.Column('name', sa.String(length=30), nullable=False),
    sa.PrimaryKeyConstraint('name'),
    schema='fastapi'
    )
    op.create_table('user',
    sa.Column('user_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('email', sa.String(length=100), nullable=False),
    sa.Column('hashed_password', sa.String(length=256), nullable=True),
    sa.Column('birth', sa.Date(), nullable=True),
    sa.Column('register_date', sa.DateTime(), nullable=False),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.Column('is_superuser', sa.Boolean(), nullable=False),
    sa.Column('sub', sa.String(length=50), nullable=True),
    sa.PrimaryKeyConstraint('user_id'),
    sa.UniqueConstraint('email'),
    schema='fastapi'
    )
    op.create_index(op.f('ix_fastapi_user_name'), 'user', ['name'], unique=False, schema='fastapi')
    op.create_table('world',
    sa.Column('world_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('creator', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=30), nullable=False),
    sa.Column('creation_date', sa.TIMESTAMP(), nullable=False),
    sa.Column('update_date', sa.TIMESTAMP(), nullable=True),
    sa.Column('description', sa.String(length=300), nullable=True),
    sa.Column('max_users', sa.Integer(), nullable=True),
    sa.Column('public', sa.Boolean(), nullable=False),
    sa.Column('allow_guests', sa.Boolean(), nullable=False),
    sa.Column('world_map', sa.LargeBinary(), nullable=False),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['creator'], ['fastapi.user.user_id'], ),
    sa.PrimaryKeyConstraint('world_id'),
    schema='fastapi'
    )
    op.create_table('event',
    sa.Column('event_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('event_type', sa.String(length=50), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('event_id'),
    schema='fastapi'
    )
    op.create_table('report_user',
    sa.Column('reported', sa.Integer(), nullable=False),
    sa.Column('reporter', sa.Integer(), nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.Column('comment', sa.String(length=300), nullable=True),
    sa.ForeignKeyConstraint(['reported'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['reporter'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('reported', 'reporter', 'world_id'),
    schema='fastapi'
    )
    op.create_table('report_world',
    sa.Column('reported', sa.Integer(), nullable=False),
    sa.Column('reporter', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.Column('comment', sa.String(length=300), nullable=True),
    sa.ForeignKeyConstraint(['reported'], ['fastapi.world.world_id'], ),
    sa.ForeignKeyConstraint(['reporter'], ['fastapi.user.user_id'], ),
    sa.PrimaryKeyConstraint('reported', 'reporter'),
    schema='fastapi'
    )
    op.create_table('role',
    sa.Column('role_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=30), nullable=False),
    sa.Column('is_default', sa.Boolean(), nullable=True),
    sa.Column('interact', sa.Boolean(), nullable=True),
    sa.Column('walk', sa.Boolean(), nullable=True),
    sa.Column('talk', sa.Boolean(), nullable=True),
    sa.Column('talk_conference', sa.Boolean(), nullable=True),
    sa.Column('world_mute', sa.Boolean(), nullable=True),
    sa.Column('role_manage', sa.Boolean(), nullable=True),
    sa.Column('conference_manage', sa.Boolean(), nullable=True),
    sa.Column('chat', sa.Boolean(), nullable=True),
    sa.Column('invite', sa.Boolean(), nullable=True),
    sa.Column('ban', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('role_id'),
    schema='fastapi'
    )
    op.create_table('world_tag',
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('tag_name', sa.String(length=30), nullable=False),
    sa.ForeignKeyConstraint(['tag_name'], ['fastapi.tag.name'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('world_id', 'tag_name'),
    schema='fastapi'
    )
    op.create_table('world_user',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('avatar', sa.String(length=50), nullable=True),
    sa.Column('join_date', sa.TIMESTAMP(), nullable=False),
    sa.Column('n_joins', sa.Integer(), nullable=False),
    sa.Column('last_join', sa.TIMESTAMP(), nullable=False),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=50), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['fastapi.role.role_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('user_id', 'world_id'),
    schema='fastapi'
    )
    op.create_index(op.f('ix_fastapi_world_user_user_id'), 'world_user', ['user_id'], unique=False, schema='fastapi')
    op.create_index(op.f('ix_fastapi_world_user_world_id'), 'world_user', ['world_id'], unique=False, schema='fastapi')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_fastapi_world_user_world_id'), table_name='world_user', schema='fastapi')
    op.drop_index(op.f('ix_fastapi_world_user_user_id'), table_name='world_user', schema='fastapi')
    op.drop_table('world_user', schema='fastapi')
    op.drop_table('world_tag', schema='fastapi')
    op.drop_table('role', schema='fastapi')
    op.drop_table('report_world', schema='fastapi')
    op.drop_table('report_user', schema='fastapi')
    op.drop_table('event', schema='fastapi')
    op.drop_table('world', schema='fastapi')
    op.drop_index(op.f('ix_fastapi_user_name'), table_name='user', schema='fastapi')
    op.drop_table('user', schema='fastapi')
    op.drop_table('tag', schema='fastapi')
    op.execute("drop schema fastapi")
    # ### end Alembic commands ###

"""First Commit

Revision ID: 9ff8b944e513
Revises: 
Create Date: 2021-05-05 15:25:23.578492

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9ff8b944e513'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("create schema fastapi")
    op.create_table('tag',
    sa.Column('name', sa.String(length=30), nullable=False),
    sa.PrimaryKeyConstraint('name'),
    schema='fastapi'
    )
    op.create_table('user',
    sa.Column('user_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('email', sa.String(length=100), nullable=False),
    sa.Column('hashed_password', sa.String(length=256), nullable=True),
    sa.Column('birth', sa.Date(), nullable=True),
    sa.Column('register_date', sa.DateTime(), nullable=False),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.Column('is_superuser', sa.Boolean(), nullable=False),
    sa.Column('sub', sa.String(length=50), nullable=True),
    sa.PrimaryKeyConstraint('user_id'),
    sa.UniqueConstraint('email'),
    schema='fastapi'
    )
    op.create_index(op.f('ix_fastapi_user_name'), 'user', ['name'], unique=False, schema='fastapi')
    op.create_table('world',
    sa.Column('world_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('creator', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=30), nullable=False),
    sa.Column('creation_date', sa.TIMESTAMP(), nullable=False),
    sa.Column('update_date', sa.TIMESTAMP(), nullable=True),
    sa.Column('description', sa.String(length=300), nullable=True),
    sa.Column('max_users', sa.Integer(), nullable=True),
    sa.Column('public', sa.Boolean(), nullable=False),
    sa.Column('allow_guests', sa.Boolean(), nullable=False),
    sa.Column('world_map', sa.LargeBinary(), nullable=False),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['creator'], ['fastapi.user.user_id'], ),
    sa.PrimaryKeyConstraint('world_id'),
    schema='fastapi'
    )
    op.create_table('event',
    sa.Column('event_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('event_type', sa.String(length=50), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('event_id'),
    schema='fastapi'
    )
    op.create_table('report_user',
    sa.Column('reported', sa.Integer(), nullable=False),
    sa.Column('reporter', sa.Integer(), nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.Column('comment', sa.String(length=300), nullable=True),
    sa.ForeignKeyConstraint(['reported'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['reporter'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('reported', 'reporter', 'world_id'),
    schema='fastapi'
    )
    op.create_table('report_world',
    sa.Column('reported', sa.Integer(), nullable=False),
    sa.Column('reporter', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.Column('comment', sa.String(length=300), nullable=True),
    sa.ForeignKeyConstraint(['reported'], ['fastapi.world.world_id'], ),
    sa.ForeignKeyConstraint(['reporter'], ['fastapi.user.user_id'], ),
    sa.PrimaryKeyConstraint('reported', 'reporter'),
    schema='fastapi'
    )
    op.create_table('role',
    sa.Column('role_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=30), nullable=False),
    sa.Column('is_default', sa.Boolean(), nullable=True),
    sa.Column('interact', sa.Boolean(), nullable=True),
    sa.Column('walk', sa.Boolean(), nullable=True),
    sa.Column('talk', sa.Boolean(), nullable=True),
    sa.Column('talk_conference', sa.Boolean(), nullable=True),
    sa.Column('world_mute', sa.Boolean(), nullable=True),
    sa.Column('role_manage', sa.Boolean(), nullable=True),
    sa.Column('conference_manage', sa.Boolean(), nullable=True),
    sa.Column('chat', sa.Boolean(), nullable=True),
    sa.Column('invite', sa.Boolean(), nullable=True),
    sa.Column('ban', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('role_id'),
    schema='fastapi'
    )
    op.create_table('world_tag',
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('tag_name', sa.String(length=30), nullable=False),
    sa.ForeignKeyConstraint(['tag_name'], ['fastapi.tag.name'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('world_id', 'tag_name'),
    schema='fastapi'
    )
    op.create_table('world_user',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('world_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.Column('avatar', sa.String(length=50), nullable=True),
    sa.Column('join_date', sa.TIMESTAMP(), nullable=False),
    sa.Column('n_joins', sa.Integer(), nullable=False),
    sa.Column('last_join', sa.TIMESTAMP(), nullable=False),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=50), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['fastapi.role.role_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['fastapi.user.user_id'], ),
    sa.ForeignKeyConstraint(['world_id'], ['fastapi.world.world_id'], ),
    sa.PrimaryKeyConstraint('user_id', 'world_id'),
    schema='fastapi'
    )
    op.create_index(op.f('ix_fastapi_world_user_user_id'), 'world_user', ['user_id'], unique=False, schema='fastapi')
    op.create_index(op.f('ix_fastapi_world_user_world_id'), 'world_user', ['world_id'], unique=False, schema='fastapi')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_fastapi_world_user_world_id'), table_name='world_user', schema='fastapi')
    op.drop_index(op.f('ix_fastapi_world_user_user_id'), table_name='world_user', schema='fastapi')
    op.drop_table('world_user', schema='fastapi')
    op.drop_table('world_tag', schema='fastapi')
    op.drop_table('role', schema='fastapi')
    op.drop_table('report_world', schema='fastapi')
    op.drop_table('report_user', schema='fastapi')
    op.drop_table('event', schema='fastapi')
    op.drop_table('world', schema='fastapi')
    op.drop_index(op.f('ix_fastapi_user_name'), table_name='user', schema='fastapi')
    op.drop_table('user', schema='fastapi')
    op.drop_table('tag', schema='fastapi')
    op.execute("drop schema fastapi")
    # ### end Alembic commands ###

First Commit  Revision ID: 9ff8b944e513 Revises:  Create Date: 2021-05-05 15:25:23.578492 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###