"""initial migration

Revision ID: dad3ecdc75db
Revises: 
Create Date: 2020-02-06 00:54:11.546750

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'artists',
        sa.Column('ArtistId', sa.Integer(), nullable=False),
        sa.Column('Name', sa.NVARCHAR(length=120), nullable=True),
        sa.PrimaryKeyConstraint('ArtistId')
    )
    op.create_table(
        'employees',
        sa.Column('EmployeeId', sa.Integer(), nullable=False),
        sa.Column('LastName', sa.NVARCHAR(length=20), nullable=False),
        sa.Column('FirstName', sa.NVARCHAR(length=20), nullable=False),
        sa.Column('Title', sa.NVARCHAR(length=30), nullable=True),
        sa.Column('ReportsTo', sa.Integer(), nullable=True),
        sa.Column('BirthDate', sa.DateTime(), nullable=True),
        sa.Column('HireDate', sa.DateTime(), nullable=True),
        sa.Column('Address', sa.NVARCHAR(length=70), nullable=True),
        sa.Column('City', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('State', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('Country', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('PostalCode', sa.NVARCHAR(length=10), nullable=True),
        sa.Column('Phone', sa.NVARCHAR(length=24), nullable=True),
        sa.Column('Fax', sa.NVARCHAR(length=24), nullable=True),
        sa.Column('Email', sa.NVARCHAR(length=60), nullable=True),
        sa.ForeignKeyConstraint(['ReportsTo'], ['employees.EmployeeId'],),
        sa.PrimaryKeyConstraint('EmployeeId')
    )
    op.create_index(
        op.f('ix_employees_ReportsTo'),
        'employees',
        ['ReportsTo'],
        unique=False
    )
    op.create_table(
        'genres',
        sa.Column('GenreId', sa.Integer(), nullable=False),
        sa.Column('Name', sa.NVARCHAR(length=120), nullable=True),
        sa.PrimaryKeyConstraint('GenreId')
    )
    op.create_table(
        'media_types',
        sa.Column('MediaTypeId', sa.Integer(), nullable=False),
        sa.Column('Name', sa.NVARCHAR(length=120), nullable=True),
        sa.PrimaryKeyConstraint('MediaTypeId')
    )
    op.create_table(
        'playlists',
        sa.Column('PlaylistId', sa.Integer(), nullable=False),
        sa.Column('Name', sa.NVARCHAR(length=120), nullable=True),
        sa.PrimaryKeyConstraint('PlaylistId')
    )
    op.create_table(
        'albums',
        sa.Column('AlbumId', sa.Integer(), nullable=False),
        sa.Column('Title', sa.NVARCHAR(length=160), nullable=False),
        sa.Column('ArtistId', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['ArtistId'], ['artists.ArtistId'],),
        sa.PrimaryKeyConstraint('AlbumId')
    )
    op.create_index(
        op.f('ix_albums_ArtistId'),
        'albums',
        ['ArtistId'],
        unique=False
    )
    op.create_table(
        'customers',
        sa.Column('CustomerId', sa.Integer(), nullable=False),
        sa.Column('FirstName', sa.NVARCHAR(length=40), nullable=False),
        sa.Column('LastName', sa.NVARCHAR(length=20), nullable=False),
        sa.Column('Company', sa.NVARCHAR(length=80), nullable=True),
        sa.Column('Address', sa.NVARCHAR(length=70), nullable=True),
        sa.Column('City', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('State', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('Country', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('PostalCode', sa.NVARCHAR(length=10), nullable=True),
        sa.Column('Phone', sa.NVARCHAR(length=24), nullable=True),
        sa.Column('Fax', sa.NVARCHAR(length=24), nullable=True),
        sa.Column('Email', sa.NVARCHAR(length=60), nullable=False),
        sa.Column('SupportRepId', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['SupportRepId'], ['employees.EmployeeId'],),
        sa.PrimaryKeyConstraint('CustomerId')
    )
    op.create_index(
        op.f('ix_customers_SupportRepId'),
        'customers',
        ['SupportRepId'],
        unique=False
    )
    op.create_table(
        'invoices',
        sa.Column('InvoiceId', sa.Integer(), nullable=False),
        sa.Column('CustomerId', sa.Integer(), nullable=False),
        sa.Column('InvoiceDate', sa.DateTime(), nullable=False),
        sa.Column('BillingAddress', sa.NVARCHAR(length=70), nullable=True),
        sa.Column('BillingCity', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('BillingState', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('BillingCountry', sa.NVARCHAR(length=40), nullable=True),
        sa.Column('BillingPostalCode', sa.NVARCHAR(length=10), nullable=True),
        sa.Column('Total', sa.Numeric(precision=10, scale=2), nullable=False),
        sa.ForeignKeyConstraint(['CustomerId'], ['customers.CustomerId'],),
        sa.PrimaryKeyConstraint('InvoiceId')
    )
    op.create_index(
        op.f('ix_invoices_CustomerId'),
        'invoices',
        ['CustomerId'],
        unique=False
    )
    op.create_table(
        'tracks',
        sa.Column('TrackId', sa.Integer(), nullable=False),
        sa.Column('Name', sa.NVARCHAR(length=200), nullable=False),
        sa.Column('AlbumId', sa.Integer(), nullable=True),
        sa.Column('MediaTypeId', sa.Integer(), nullable=False),
        sa.Column('GenreId', sa.Integer(), nullable=True),
        sa.Column('Composer', sa.NVARCHAR(length=220), nullable=True),
        sa.Column('Milliseconds', sa.Integer(), nullable=False),
        sa.Column('Bytes', sa.Integer(), nullable=True),
        sa.Column(
            'UnitPrice',
            sa.Numeric(precision=10, scale=2),
            nullable=False
        ),
        sa.ForeignKeyConstraint(['AlbumId'], ['albums.AlbumId'],),
        sa.ForeignKeyConstraint(['GenreId'], ['genres.GenreId'],),
        sa.ForeignKeyConstraint(['MediaTypeId'], ['media_types.MediaTypeId'],),
        sa.PrimaryKeyConstraint('TrackId')
    )
    op.create_index(
        op.f('ix_tracks_AlbumId'),
        'tracks',
        ['AlbumId'],
        unique=False
    )
    op.create_index(
        op.f('ix_tracks_GenreId'),
        'tracks',
        ['GenreId'],
        unique=False
    )
    op.create_index(
        op.f('ix_tracks_MediaTypeId'),
        'tracks',
        ['MediaTypeId'],
        unique=False
    )
    op.create_table(
        'invoice_items',
        sa.Column('InvoiceLineId', sa.Integer(), nullable=False),
        sa.Column('InvoiceId', sa.Integer(), nullable=False),
        sa.Column('TrackId', sa.Integer(), nullable=False),
        sa.Column(
            'UnitPrice',
            sa.Numeric(precision=10, scale=2),
            nullable=False
        ),
        sa.Column('Quantity', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['InvoiceId'], ['invoices.InvoiceId'],),
        sa.ForeignKeyConstraint(['TrackId'], ['tracks.TrackId'],),
        sa.PrimaryKeyConstraint('InvoiceLineId')
    )
    op.create_index(
        op.f('ix_invoice_items_InvoiceId'),
        'invoice_items',
        ['InvoiceId'],
        unique=False
    )
    op.create_index(
        op.f('ix_invoice_items_TrackId'),
        'invoice_items',
        ['TrackId'],
        unique=False
    )
    op.create_table(
        'playlist_track',
        sa.Column('PlaylistId', sa.Integer(), nullable=False),
        sa.Column('TrackId', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['PlaylistId'], ['playlists.PlaylistId'],),
        sa.ForeignKeyConstraint(['TrackId'], ['tracks.TrackId'],),
        sa.PrimaryKeyConstraint('PlaylistId', 'TrackId')
    )
    op.create_index(
        op.f('ix_playlist_track_TrackId'),
        'playlist_track',
        ['TrackId'],
        unique=False
    )


def downgrade():
    op.drop_index(
        op.f('ix_playlist_track_TrackId'),
        table_name='playlist_track'
    )
    op.drop_table('playlist_track')
    op.drop_index(op.f('ix_invoice_items_TrackId'), table_name='invoice_items')
    op.drop_index(
        op.f('ix_invoice_items_InvoiceId'),
        table_name='invoice_items'
    )
    op.drop_table('invoice_items')
    op.drop_index(op.f('ix_tracks_MediaTypeId'), table_name='tracks')
    op.drop_index(op.f('ix_tracks_GenreId'), table_name='tracks')
    op.drop_index(op.f('ix_tracks_AlbumId'), table_name='tracks')
    op.drop_table('tracks')
    op.drop_index(op.f('ix_invoices_CustomerId'), table_name='invoices')
    op.drop_table('invoices')
    op.drop_index(op.f('ix_customers_SupportRepId'), table_name='customers')
    op.drop_table('customers')
    op.drop_index(op.f('ix_albums_ArtistId'), table_name='albums')
    op.drop_table('albums')
    op.drop_table('playlists')
    op.drop_table('media_types')
    op.drop_table('genres')
    op.drop_index(op.f('ix_employees_ReportsTo'), table_name='employees')
    op.drop_table('employees')
    op.drop_table('artists')
