"""create new node_cache table

Revision ID: 0208c10ea67f
Revises: 503a2cef2378
Create Date: 2018-03-28 13:31:34.018012

"""

# revision identifiers, used by Alembic.
revision = "0208c10ea67f"
down_revision = "503a2cef2378"
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


from sqlalchemy_utils import UUIDType as TempUUIDType

UUIDType = TempUUIDType(binary=False)


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "rb_node_cache",
        sa.Column("id", UUIDType, nullable=False),
        sa.Column("node_id", UUIDType, nullable=True),
        sa.Column("valid", sa.Boolean(), nullable=True),
        sa.Column("updated_timestamp", sa.BigInteger(), nullable=False),
        sa.Column("json_stats", sa.UnicodeText(), nullable=True),
        sa.ForeignKeyConstraint(["node_id"], ["rb_node.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_rb_node_cache_id"), "rb_node_cache", ["id"], unique=False)
    op.create_index(
        op.f("ix_rb_node_cache_node_id"), "rb_node_cache", ["node_id"], unique=False
    )
    op.drop_table("rb_root_cache")


def downgrade():
    op.create_table(
        "rb_root_cache",
        sa.Column("id", sa.CHAR(length=32), nullable=False),
        sa.Column("root_id", sa.CHAR(length=32), nullable=True),
        sa.Column("valid", sa.BOOLEAN(), nullable=True),
        sa.Column("updated_timestamp", sa.BIGINT(), nullable=False),
        sa.Column("json_stats", sa.TEXT(), nullable=True),
        sa.CheckConstraint(u"valid IN (0, 1)"),
        sa.ForeignKeyConstraint(["root_id"], [u"rb_node.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.drop_index(op.f("ix_rb_node_cache_node_id"), table_name="rb_node_cache")
    op.drop_index(op.f("ix_rb_node_cache_id"), table_name="rb_node_cache")
    op.drop_table("rb_node_cache")
