"""Run

Revision ID: 09964c92ec59
Revises: 
Create Date: 2017-09-05 13:53:29.343139

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '09964c92ec59'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('News',
    sa.Column('NewsID', sa.Integer(), nullable=False),
    sa.Column('Title', sa.String(length=255), nullable=False),
    sa.Column('Contents', sa.Text(), nullable=False),
    sa.Column('Author', sa.String(length=255), nullable=False),
    sa.Column('Created', sa.DateTime(), nullable=False),
    sa.Column('Updated', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('NewsID')
    )
    op.create_table('NewsCategories',
    sa.Column('NewsCategoryID', sa.Integer(), nullable=False),
    sa.Column('Category', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('NewsCategoryID')
    )
    op.create_table('People',
    sa.Column('PersonID', sa.Integer(), nullable=False),
    sa.Column('Name', sa.String(length=190), nullable=False),
    sa.PrimaryKeyConstraint('PersonID'),
    sa.UniqueConstraint('Name')
    )
    op.create_table('ReleaseCategories',
    sa.Column('ReleaseCategoryID', sa.Integer(), nullable=False),
    sa.Column('ReleaseCategory', sa.String(length=200), nullable=True),
    sa.PrimaryKeyConstraint('ReleaseCategoryID')
    )
    op.create_table('ReleaseFormats',
    sa.Column('ReleaseFormatID', sa.Integer(), nullable=False),
    sa.Column('Title', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('ReleaseFormatID')
    )
    op.create_table('Releases',
    sa.Column('ReleaseID', sa.Integer(), nullable=False),
    sa.Column('Title', sa.String(length=200), nullable=False),
    sa.Column('Date', sa.DateTime(), nullable=False),
    sa.Column('Artist', sa.String(length=200), nullable=False),
    sa.Column('Credits', sa.Text(), nullable=True),
    sa.Column('Created', sa.DateTime(), nullable=True),
    sa.Column('Updated', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('ReleaseID')
    )
    op.create_table('Songs',
    sa.Column('SongID', sa.Integer(), nullable=False),
    sa.Column('Title', sa.String(length=190), nullable=False),
    sa.Column('Duration', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('SongID'),
    sa.UniqueConstraint('Title')
    )
    op.create_table('Users',
    sa.Column('UserID', sa.Integer(), nullable=False),
    sa.Column('Name', sa.String(length=200), nullable=False),
    sa.Column('Email', sa.String(length=200), nullable=True),
    sa.Column('Username', sa.String(length=200), nullable=False),
    sa.Column('Password', sa.Text(), nullable=False),
    sa.Column('Created', sa.DateTime(), nullable=True),
    sa.Column('Updated', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('UserID')
    )
    op.create_table('UsersAccessLevels',
    sa.Column('UsersAccessLevelID', sa.Integer(), nullable=False),
    sa.Column('LevelName', sa.String(length=100), nullable=False),
    sa.Column('AccessDescription', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('UsersAccessLevelID')
    )
    op.create_table('NewsCategoriesMapping',
    sa.Column('NewsCategoriesMappingID', sa.Integer(), nullable=False),
    sa.Column('NewsID', sa.Integer(), nullable=False),
    sa.Column('NewsCategoryID', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['NewsID'], ['News.NewsID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('NewsCategoriesMappingID')
    )
    op.create_table('NewsComments',
    sa.Column('NewsCommentID', sa.Integer(), nullable=False),
    sa.Column('NewsID', sa.Integer(), nullable=False),
    sa.Column('UserID', sa.Integer(), nullable=False),
    sa.Column('Comment', sa.String(length=1000), nullable=False),
    sa.Column('Created', sa.DateTime(), nullable=False),
    sa.Column('Updated', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['NewsID'], ['News.NewsID'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['UserID'], ['Users.UserID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('NewsCommentID')
    )
    op.create_table('ReleasesCategoriesMapping',
    sa.Column('ReleasesCategoriesMappingID', sa.Integer(), nullable=False),
    sa.Column('ReleaseID', sa.Integer(), nullable=False),
    sa.Column('ReleaseCategoryID', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['ReleaseCategoryID'], ['ReleaseCategories.ReleaseCategoryID'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['ReleaseID'], ['Releases.ReleaseID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('ReleasesCategoriesMappingID')
    )
    op.create_table('ReleasesFormatsMapping',
    sa.Column('ReleaseFormatsMappingID', sa.Integer(), nullable=False),
    sa.Column('ReleaseFormatID', sa.Integer(), nullable=False),
    sa.Column('ReleaseID', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['ReleaseFormatID'], ['ReleaseFormats.ReleaseFormatID'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['ReleaseID'], ['Releases.ReleaseID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('ReleaseFormatsMappingID')
    )
    op.create_table('ReleasesPeopleMapping',
    sa.Column('ReleasesPeopleMappingID', sa.Integer(), nullable=False),
    sa.Column('ReleaseID', sa.Integer(), nullable=False),
    sa.Column('PersonID', sa.Integer(), nullable=False),
    sa.Column('Instruments', sa.String(length=500), nullable=False),
    sa.ForeignKeyConstraint(['PersonID'], ['People.PersonID'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['ReleaseID'], ['Releases.ReleaseID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('ReleasesPeopleMappingID')
    )
    op.create_table('ReleasesSongsMapping',
    sa.Column('ReleasesSongsMappingID', sa.Integer(), nullable=False),
    sa.Column('ReleaseID', sa.Integer(), nullable=False),
    sa.Column('SongID', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['ReleaseID'], ['Releases.ReleaseID'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['SongID'], ['Songs.SongID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('ReleasesSongsMappingID')
    )
    op.create_table('UsersAccessMapping',
    sa.Column('UsersAccessMappingID', sa.Integer(), nullable=False),
    sa.Column('UserID', sa.Integer(), nullable=False),
    sa.Column('UsersAccessLevelID', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['UserID'], ['Users.UserID'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['UsersAccessLevelID'], ['UsersAccessLevels.UsersAccessLevelID'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('UsersAccessMappingID')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('UsersAccessMapping')
    op.drop_table('ReleasesSongsMapping')
    op.drop_table('ReleasesPeopleMapping')
    op.drop_table('ReleasesFormatsMapping')
    op.drop_table('ReleasesCategoriesMapping')
    op.drop_table('NewsComments')
    op.drop_table('NewsCategoriesMapping')
    op.drop_table('UsersAccessLevels')
    op.drop_table('Users')
    op.drop_table('Songs')
    op.drop_table('Releases')
    op.drop_table('ReleaseFormats')
    op.drop_table('ReleaseCategories')
    op.drop_table('People')
    op.drop_table('NewsCategories')
    op.drop_table('News')
    # ### end Alembic commands ###
