"""add user tags and documents

Revision ID: a359a216ead7
Revises: efcd5b3e0204
Create Date: 2016-09-26 21:45:37.412273

"""

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

from alembic import op
import sqlalchemy as sa
from sqlalchemy.schema import Sequence, CreateSequence


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_tags',
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('user_id', sa.BigInteger(), nullable=True),
    sa.Column('name', sa.Text(), nullable=True),
    sa.Column('provenance', sa.Text(), nullable=True),
    sa.Column('topic_id', sa.BigInteger(), nullable=True),
    sa.Column('topic_table', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute(CreateSequence(Sequence('user_tag_id_seq')))
    op.create_index(op.f('ix_user_tags_user_id'), 'user_tags', ['user_id'], unique=False)
    op.create_index('topic_table_id_index', 'user_tags', ['topic_table', 'topic_id'], unique=False)
    op.create_table('user_document_tags',
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('doc_id', sa.BigInteger(), nullable=True),
    sa.Column('user_tag_id', sa.BigInteger(), nullable=True),
    sa.Column('user_id', sa.BigInteger(), nullable=True),
    sa.Column('is_positive', sa.Boolean(), nullable=True),
    sa.Column('display_style', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['user_tag_id'], ['user_tags.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute(CreateSequence(Sequence('user_document_tag_id_seq')))
    op.create_index(op.f('ix_user_document_tags_doc_id'), 'user_document_tags', ['doc_id'], unique=False)
    op.create_index('user_id_doc_id_is_positive_index', 'user_document_tags', ['user_id', 'doc_id', 'is_positive'], unique=False)
    op.create_index('user_tag_id_display_style_index', 'user_document_tags', ['user_tag_id', 'display_style'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('user_tag_id_display_style_index', table_name='user_document_tags')
    op.drop_index('user_id_doc_id_is_positive_index', table_name='user_document_tags')
    op.drop_index(op.f('ix_user_document_tags_doc_id'), table_name='user_document_tags')
    op.drop_table('user_document_tags')
    op.drop_index('topic_table_id_index', table_name='user_tags')
    op.drop_index(op.f('ix_user_tags_user_id'), table_name='user_tags')
    op.drop_table('user_tags')
    ### end Alembic commands ###
