"""books table

Revision ID: 0af7310c8a58
Revises: 9<PASSWORD>
Create Date: 2018-09-17 16:02:16.075305

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0af7310c8a58'
down_revision = '9<PASSWORD>a<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('authors',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.Column('sort', sa.String(length=128), nullable=True),
    sa.Column('link', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('books',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=128), nullable=True),
    sa.Column('sort', sa.String(length=128), nullable=True),
    sa.Column('author_sort', sa.String(length=128), nullable=True),
    sa.Column('timestamp', sa.String(length=128), nullable=True),
    sa.Column('pubdate', sa.String(length=128), nullable=True),
    sa.Column('series_index', sa.String(length=128), nullable=True),
    sa.Column('last_modified', sa.String(length=128), nullable=True),
    sa.Column('path', sa.String(length=128), nullable=True),
    sa.Column('has_cover', sa.Boolean(), nullable=True),
    sa.Column('uuid', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('languages',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('lang_code', sa.String(length=20), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('publishers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.Column('sort', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('ratings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('rating', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('series',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.Column('sort', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('tags',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=32), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('bookmark',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('book_id', sa.Integer(), nullable=True),
    sa.Column('format', sa.String(length=20), nullable=True),
    sa.Column('bookmark_key', sa.String(length=128), nullable=True),
    sa.ForeignKeyConstraint(['book_id'], ['books.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('books_authors_link',
    sa.Column('book', sa.Integer(), nullable=False),
    sa.Column('author', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['author'], ['authors.id'], ),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.PrimaryKeyConstraint('book', 'author')
    )
    op.create_table('books_languages_link',
    sa.Column('book', sa.Integer(), nullable=False),
    sa.Column('lang_code', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.ForeignKeyConstraint(['lang_code'], ['languages.id'], ),
    sa.PrimaryKeyConstraint('book', 'lang_code')
    )
    op.create_table('books_publishers_link',
    sa.Column('book', sa.Integer(), nullable=False),
    sa.Column('publisher', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.ForeignKeyConstraint(['publisher'], ['publishers.id'], ),
    sa.PrimaryKeyConstraint('book', 'publisher')
    )
    op.create_table('books_ratings_link',
    sa.Column('book', sa.Integer(), nullable=False),
    sa.Column('rating', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.ForeignKeyConstraint(['rating'], ['ratings.id'], ),
    sa.PrimaryKeyConstraint('book', 'rating')
    )
    op.create_table('books_series_link',
    sa.Column('book', sa.Integer(), nullable=False),
    sa.Column('series', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.ForeignKeyConstraint(['series'], ['series.id'], ),
    sa.PrimaryKeyConstraint('book', 'series')
    )
    op.create_table('books_tags_link',
    sa.Column('book', sa.Integer(), nullable=False),
    sa.Column('tag', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.ForeignKeyConstraint(['tag'], ['tags.id'], ),
    sa.PrimaryKeyConstraint('book', 'tag')
    )
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('book', sa.Integer(), nullable=True),
    sa.Column('text', sa.String(length=64), nullable=True),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('data',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('book', sa.Integer(), nullable=True),
    sa.Column('format', sa.String(length=20), nullable=True),
    sa.Column('uncompressed_size', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('identifiers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('type', sa.String(length=128), nullable=True),
    sa.Column('val', sa.String(length=128), nullable=True),
    sa.Column('book', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['book'], ['books.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('read_book',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('book_id', sa.Integer(), nullable=True),
    sa.Column('is_read', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['book_id'], ['books.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('users', sa.Column('kindle_email', sa.String(length=120), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'kindle_email')
    op.drop_table('read_book')
    op.drop_table('identifiers')
    op.drop_table('data')
    op.drop_table('comments')
    op.drop_table('books_tags_link')
    op.drop_table('books_series_link')
    op.drop_table('books_ratings_link')
    op.drop_table('books_publishers_link')
    op.drop_table('books_languages_link')
    op.drop_table('books_authors_link')
    op.drop_table('bookmark')
    op.drop_table('tags')
    op.drop_table('series')
    op.drop_table('ratings')
    op.drop_table('publishers')
    op.drop_table('languages')
    op.drop_table('books')
    op.drop_table('authors')
    # ### end Alembic commands ###
