<filename>alembic/versions/7d4def039304_create_models.py
"""create models

Revision ID: 7d4def039304
Revises:
Create Date: 2021-06-09 21:23:20.191168

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '7d4def<PASSWORD>'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('author',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('first_name', sa.String(), nullable=True),
                    sa.Column('last_name', sa.String(), nullable=True),
                    sa.Column('middle_name', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_author_first_name'), 'author', ['first_name'], unique=False)
    op.create_index(op.f('ix_author_last_name'), 'author', ['last_name'], unique=False)
    op.create_index(op.f('ix_author_middle_name'), 'author', ['middle_name'], unique=False)
    op.create_table('category',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(), nullable=True),
                    sa.Column('parent_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(['parent_id'], ['category.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_category_name'), 'category', ['name'], unique=False)
    op.create_index(op.f('ix_category_parent_id'), 'category', ['parent_id'], unique=False)
    op.create_table('document',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('title', sa.String(), nullable=True),
                    sa.Column('path', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_document_path'), 'document', ['path'], unique=False)
    op.create_index(op.f('ix_document_title'), 'document', ['title'], unique=False)
    op.create_table('document_type',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('title', sa.String(), nullable=True),
                    sa.Column('description', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_document_type_description'), 'document_type', ['description'], unique=False)
    op.create_index(op.f('ix_document_type_title'), 'document_type', ['title'], unique=False)
    op.create_table('shelf',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(), nullable=True),
                    sa.Column('description', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_shelf_description'), 'shelf', ['description'], unique=False)
    op.create_index(op.f('ix_shelf_name'), 'shelf', ['name'], unique=False)
    op.create_table('author_documents',
                    sa.Column('author_id', sa.Integer(), nullable=False),
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['author_id'], ['author.id'], ),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.PrimaryKeyConstraint('author_id', 'document_id')
                    )
    op.create_table('document_categories',
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.Column('category_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.PrimaryKeyConstraint('document_id', 'category_id')
                    )
    op.create_table('document_types',
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.Column('document_type_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.ForeignKeyConstraint(['document_type_id'], ['document_type.id'], ),
                    sa.PrimaryKeyConstraint('document_id', 'document_type_id')
                    )
    op.create_table('shelf_documents',
                    sa.Column('shelf_id', sa.Integer(), nullable=False),
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.ForeignKeyConstraint(['shelf_id'], ['shelf.id'], ),
                    sa.PrimaryKeyConstraint('shelf_id', 'document_id')
                    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('shelf_documents')
    op.drop_table('document_types')
    op.drop_table('document_categories')
    op.drop_table('author_documents')
    op.drop_index(op.f('ix_shelf_name'), table_name='shelf')
    op.drop_index(op.f('ix_shelf_description'), table_name='shelf')
    op.drop_table('shelf')
    op.drop_index(op.f('ix_document_type_title'), table_name='document_type')
    op.drop_index(op.f('ix_document_type_description'), table_name='document_type')
    op.drop_table('document_type')
    op.drop_index(op.f('ix_document_title'), table_name='document')
    op.drop_index(op.f('ix_document_path'), table_name='document')
    op.drop_table('document')
    op.drop_index(op.f('ix_category_parent_id'), table_name='category')
    op.drop_index(op.f('ix_category_name'), table_name='category')
    op.drop_table('category')
    op.drop_index(op.f('ix_author_middle_name'), table_name='author')
    op.drop_index(op.f('ix_author_last_name'), table_name='author')
    op.drop_index(op.f('ix_author_first_name'), table_name='author')
    op.drop_table('author')
    # ### end Alembic commands ###

<filename>alembic/versions/7d4def039304_create_models.py
"""create models

Revision ID: 7d4def039304
Revises:
Create Date: 2021-06-09 21:23:20.191168

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '7d4def<PASSWORD>'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('author',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('first_name', sa.String(), nullable=True),
                    sa.Column('last_name', sa.String(), nullable=True),
                    sa.Column('middle_name', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_author_first_name'), 'author', ['first_name'], unique=False)
    op.create_index(op.f('ix_author_last_name'), 'author', ['last_name'], unique=False)
    op.create_index(op.f('ix_author_middle_name'), 'author', ['middle_name'], unique=False)
    op.create_table('category',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(), nullable=True),
                    sa.Column('parent_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(['parent_id'], ['category.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_category_name'), 'category', ['name'], unique=False)
    op.create_index(op.f('ix_category_parent_id'), 'category', ['parent_id'], unique=False)
    op.create_table('document',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('title', sa.String(), nullable=True),
                    sa.Column('path', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_document_path'), 'document', ['path'], unique=False)
    op.create_index(op.f('ix_document_title'), 'document', ['title'], unique=False)
    op.create_table('document_type',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('title', sa.String(), nullable=True),
                    sa.Column('description', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_document_type_description'), 'document_type', ['description'], unique=False)
    op.create_index(op.f('ix_document_type_title'), 'document_type', ['title'], unique=False)
    op.create_table('shelf',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(), nullable=True),
                    sa.Column('description', sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_shelf_description'), 'shelf', ['description'], unique=False)
    op.create_index(op.f('ix_shelf_name'), 'shelf', ['name'], unique=False)
    op.create_table('author_documents',
                    sa.Column('author_id', sa.Integer(), nullable=False),
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['author_id'], ['author.id'], ),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.PrimaryKeyConstraint('author_id', 'document_id')
                    )
    op.create_table('document_categories',
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.Column('category_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.PrimaryKeyConstraint('document_id', 'category_id')
                    )
    op.create_table('document_types',
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.Column('document_type_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.ForeignKeyConstraint(['document_type_id'], ['document_type.id'], ),
                    sa.PrimaryKeyConstraint('document_id', 'document_type_id')
                    )
    op.create_table('shelf_documents',
                    sa.Column('shelf_id', sa.Integer(), nullable=False),
                    sa.Column('document_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['document_id'], ['document.id'], ),
                    sa.ForeignKeyConstraint(['shelf_id'], ['shelf.id'], ),
                    sa.PrimaryKeyConstraint('shelf_id', 'document_id')
                    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('shelf_documents')
    op.drop_table('document_types')
    op.drop_table('document_categories')
    op.drop_table('author_documents')
    op.drop_index(op.f('ix_shelf_name'), table_name='shelf')
    op.drop_index(op.f('ix_shelf_description'), table_name='shelf')
    op.drop_table('shelf')
    op.drop_index(op.f('ix_document_type_title'), table_name='document_type')
    op.drop_index(op.f('ix_document_type_description'), table_name='document_type')
    op.drop_table('document_type')
    op.drop_index(op.f('ix_document_title'), table_name='document')
    op.drop_index(op.f('ix_document_path'), table_name='document')
    op.drop_table('document')
    op.drop_index(op.f('ix_category_parent_id'), table_name='category')
    op.drop_index(op.f('ix_category_name'), table_name='category')
    op.drop_table('category')
    op.drop_index(op.f('ix_author_middle_name'), table_name='author')
    op.drop_index(op.f('ix_author_last_name'), table_name='author')
    op.drop_index(op.f('ix_author_first_name'), table_name='author')
    op.drop_table('author')
    # ### end Alembic commands ###

create models  Revision ID: 7d4def039304 Revises: Create Date: 2021-06-09 21:23:20.191168 # 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 ###