<gh_stars>1-10
"""Initial migration

Revision ID: <KEY>
Revises:
Create Date: 2021-01-04 09:56:20.616048

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "<KEY>"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "documents",
        sa.Column("id", sa.String(), nullable=False),
        sa.Column("version", sa.String(), nullable=True),
        sa.Column("source", sa.String(), nullable=True),
        sa.Column("title", sa.String(), nullable=True),
        sa.Column("document_type", sa.String(), nullable=True),
        sa.Column("publication_date", sa.Date(), nullable=True),
        sa.Column("update_date", sa.Date(), nullable=True),
        sa.Column("modified_date", sa.DateTime(), nullable=True),
        sa.Column("urls", postgresql.ARRAY(sa.String(), dimensions=1), nullable=True),
        sa.Column("summary", sa.String(), nullable=True),
        sa.Column("raw_text", sa.String(), nullable=True),
        sa.Column("raw_text_format", sa.String(), nullable=True),
        sa.Column("parsed_text", sa.String(), nullable=True),
        sa.Column("document_subtype", sa.String(), nullable=True),
        sa.Column(
            "authors", postgresql.ARRAY(sa.String(), dimensions=1), nullable=True
        ),
        sa.Column("language", sa.String(), nullable=True),
        sa.Column(
            "keywords", postgresql.ARRAY(sa.String(), dimensions=1), nullable=True
        ),
        sa.Column("tags", postgresql.ARRAY(sa.String(), dimensions=1), nullable=True),
        sa.Column("extra", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_documents_id"), "documents", ["id"], unique=False)
    op.create_index(
        op.f("ix_documents_modified_date"), "documents", ["modified_date"], unique=False
    )
    op.create_index(
        op.f("ix_documents_publication_date"),
        "documents",
        ["publication_date"],
        unique=False,
    )
    op.create_index(
        op.f("ix_documents_update_date"), "documents", ["update_date"], unique=False
    )
    op.create_table(
        "entities",
        sa.Column("id", sa.String(), nullable=False),
        sa.Column("preferred_name", sa.String(), nullable=False),
        sa.Column("entity_type", sa.String(), nullable=True),
        sa.Column(
            "synonyms", postgresql.ARRAY(sa.String(), dimensions=1), nullable=True
        ),
        sa.Column("source", sa.String(), nullable=True),
        sa.Column("modified_date", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_entities_id"), "entities", ["id"], unique=False)
    op.create_index(
        op.f("ix_entities_modified_date"), "entities", ["modified_date"], unique=False
    )
    op.create_index(
        op.f("ix_entities_preferred_name"), "entities", ["preferred_name"], unique=False
    )
    op.create_table(
        "users",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("email", sa.String(), nullable=True),
        sa.Column("username", sa.String(), nullable=True),
        sa.Column("hashed_password", sa.String(), nullable=True),
        sa.Column("created_date", sa.DateTime(), nullable=True),
        sa.Column("last_login", sa.DateTime(), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=True),
        sa.Column("is_superuser", sa.Boolean(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_users_created_date"), "users", ["created_date"], unique=False
    )
    op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
    op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
    op.create_index(op.f("ix_users_last_login"), "users", ["last_login"], unique=False)
    op.create_table(
        "entity_mentions",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("document_id", sa.String(), nullable=False),
        sa.Column("entity_id", sa.String(), nullable=False),
        sa.Column("text", sa.String(), nullable=True),
        sa.Column("document_section", sa.String(), nullable=True),
        sa.Column("start_char", sa.Integer(), nullable=True),
        sa.Column("end_char", sa.Integer(), nullable=True),
        sa.Column("start_token", sa.Integer(), nullable=True),
        sa.Column("end_token", sa.Integer(), nullable=True),
        sa.Column("source", sa.String(), nullable=True),
        sa.Column("modified_date", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["document_id"],
            ["documents.id"],
        ),
        sa.ForeignKeyConstraint(
            ["entity_id"],
            ["entities.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_entity_mentions_document_id"),
        "entity_mentions",
        ["document_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_entity_mentions_entity_id"),
        "entity_mentions",
        ["entity_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_entity_mentions_id"), "entity_mentions", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_entity_mentions_modified_date"),
        "entity_mentions",
        ["modified_date"],
        unique=False,
    )
    op.create_index(
        op.f("ix_entity_mentions_source"), "entity_mentions", ["source"], unique=False
    )
    op.create_table(
        "ner_evaluations",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("document_id", sa.String(), nullable=False),
        sa.Column("document_section", sa.String(), nullable=True),
        sa.Column("ner_source", sa.String(), nullable=True),
        sa.Column("annotation_source", sa.String(), nullable=True),
        sa.Column("tp", sa.Integer(), nullable=True),
        sa.Column("tn", sa.Integer(), nullable=True),
        sa.Column("fp", sa.Integer(), nullable=True),
        sa.Column("fn", sa.Integer(), nullable=True),
        sa.Column("precision", sa.Float(), nullable=True),
        sa.Column("recall", sa.Float(), nullable=True),
        sa.Column("fscore", sa.Float(), nullable=True),
        sa.ForeignKeyConstraint(
            ["document_id"],
            ["documents.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_ner_evaluations_annotation_source"),
        "ner_evaluations",
        ["annotation_source"],
        unique=False,
    )
    op.create_index(
        op.f("ix_ner_evaluations_document_id"),
        "ner_evaluations",
        ["document_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_ner_evaluations_id"), "ner_evaluations", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_ner_evaluations_ner_source"),
        "ner_evaluations",
        ["ner_source"],
        unique=False,
    )
    op.create_table(
        "user_ratings",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("document_id", sa.String(), nullable=False),
        sa.Column("value", sa.Float(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("modified_date", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["document_id"],
            ["documents.id"],
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_user_ratings_document_id"),
        "user_ratings",
        ["document_id"],
        unique=False,
    )
    op.create_index(op.f("ix_user_ratings_id"), "user_ratings", ["id"], unique=False)
    op.create_index(
        op.f("ix_user_ratings_modified_date"),
        "user_ratings",
        ["modified_date"],
        unique=False,
    )
    op.create_index(
        op.f("ix_user_ratings_user_id"), "user_ratings", ["user_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_user_ratings_user_id"), table_name="user_ratings")
    op.drop_index(op.f("ix_user_ratings_modified_date"), table_name="user_ratings")
    op.drop_index(op.f("ix_user_ratings_id"), table_name="user_ratings")
    op.drop_index(op.f("ix_user_ratings_document_id"), table_name="user_ratings")
    op.drop_table("user_ratings")
    op.drop_index(op.f("ix_ner_evaluations_ner_source"), table_name="ner_evaluations")
    op.drop_index(op.f("ix_ner_evaluations_id"), table_name="ner_evaluations")
    op.drop_index(op.f("ix_ner_evaluations_document_id"), table_name="ner_evaluations")
    op.drop_index(
        op.f("ix_ner_evaluations_annotation_source"), table_name="ner_evaluations"
    )
    op.drop_table("ner_evaluations")
    op.drop_index(op.f("ix_entity_mentions_source"), table_name="entity_mentions")
    op.drop_index(
        op.f("ix_entity_mentions_modified_date"), table_name="entity_mentions"
    )
    op.drop_index(op.f("ix_entity_mentions_id"), table_name="entity_mentions")
    op.drop_index(op.f("ix_entity_mentions_entity_id"), table_name="entity_mentions")
    op.drop_index(op.f("ix_entity_mentions_document_id"), table_name="entity_mentions")
    op.drop_table("entity_mentions")
    op.drop_index(op.f("ix_users_last_login"), table_name="users")
    op.drop_index(op.f("ix_users_id"), table_name="users")
    op.drop_index(op.f("ix_users_email"), table_name="users")
    op.drop_index(op.f("ix_users_created_date"), table_name="users")
    op.drop_table("users")
    op.drop_index(op.f("ix_entities_preferred_name"), table_name="entities")
    op.drop_index(op.f("ix_entities_modified_date"), table_name="entities")
    op.drop_index(op.f("ix_entities_id"), table_name="entities")
    op.drop_table("entities")
    op.drop_index(op.f("ix_documents_update_date"), table_name="documents")
    op.drop_index(op.f("ix_documents_publication_date"), table_name="documents")
    op.drop_index(op.f("ix_documents_modified_date"), table_name="documents")
    op.drop_index(op.f("ix_documents_id"), table_name="documents")
    op.drop_table("documents")
    # ### end Alembic commands ###
