<reponame>andrewsmike/jasmine<filename>jasmine-models/migrations/versions/c8d7ac3697f5_add_materialization_model.py
"""Add materialization model.

Revision ID: <KEY>
Revises: 8817963694c9
Create Date: 2021-11-25 20:33:29.874219

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

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "materializations",
        sa.Column("materialization_id", sa.BigInteger(), nullable=False),
        sa.Column(
            "materialization_type", sa.Enum("view", "history_table"), nullable=False
        ),
        sa.Column("state", sa.String(length=64), nullable=False),
        sa.Column("config", sa.JSON(), nullable=False),
        sa.Column("view_id", sa.BigInteger(), nullable=False),
        sa.ForeignKeyConstraint(
            ["view_id"],
            ["views.view_id"],
        ),
        sa.PrimaryKeyConstraint("materialization_id"),
        sa.UniqueConstraint("view_id", "materialization_type"),
    )
    op.drop_table("_jsmn_cdc_users")
    op.create_foreign_key(
        "backend_event_materialization",
        "backend_events",
        "materializations",
        ["materialization_id"],
        ["materialization_id"],
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        "backend_event_materialization", "backend_events", type_="foreignkey"
    )
    op.create_table(
        "_jsmn_cdc_users",
        sa.Column("auto_id", mysql.BIGINT(), autoincrement=True, nullable=False),
        sa.Column(
            "op_type",
            mysql.ENUM("INSERT", "INSERT_UPDATE", "DELETE", "DELETE_UPDATE"),
            nullable=False,
        ),
        sa.Column("user_id", mysql.BIGINT(), autoincrement=False, nullable=True),
        sa.Column("email", mysql.VARCHAR(length=96), nullable=True),
        sa.Column("name", mysql.VARCHAR(length=96), nullable=True),
        sa.Column(
            "default_project_id", mysql.BIGINT(), autoincrement=False, nullable=True
        ),
        sa.Column(
            "organization_id", mysql.BIGINT(), autoincrement=False, nullable=True
        ),
        sa.Column("event_ts", mysql.BIGINT(), autoincrement=False, nullable=False),
        sa.PrimaryKeyConstraint("auto_id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.drop_table("materializations")
    # ### end Alembic commands ###

"""Add materialization model.

Revision ID: <KEY>
Revises: 8817963694c9
Create Date: 2021-11-25 20:33:29.874219

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

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "materializations",
        sa.Column("materialization_id", sa.BigInteger(), nullable=False),
        sa.Column(
            "materialization_type", sa.Enum("view", "history_table"), nullable=False
        ),
        sa.Column("state", sa.String(length=64), nullable=False),
        sa.Column("config", sa.JSON(), nullable=False),
        sa.Column("view_id", sa.BigInteger(), nullable=False),
        sa.ForeignKeyConstraint(
            ["view_id"],
            ["views.view_id"],
        ),
        sa.PrimaryKeyConstraint("materialization_id"),
        sa.UniqueConstraint("view_id", "materialization_type"),
    )
    op.drop_table("_jsmn_cdc_users")
    op.create_foreign_key(
        "backend_event_materialization",
        "backend_events",
        "materializations",
        ["materialization_id"],
        ["materialization_id"],
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        "backend_event_materialization", "backend_events", type_="foreignkey"
    )
    op.create_table(
        "_jsmn_cdc_users",
        sa.Column("auto_id", mysql.BIGINT(), autoincrement=True, nullable=False),
        sa.Column(
            "op_type",
            mysql.ENUM("INSERT", "INSERT_UPDATE", "DELETE", "DELETE_UPDATE"),
            nullable=False,
        ),
        sa.Column("user_id", mysql.BIGINT(), autoincrement=False, nullable=True),
        sa.Column("email", mysql.VARCHAR(length=96), nullable=True),
        sa.Column("name", mysql.VARCHAR(length=96), nullable=True),
        sa.Column(
            "default_project_id", mysql.BIGINT(), autoincrement=False, nullable=True
        ),
        sa.Column(
            "organization_id", mysql.BIGINT(), autoincrement=False, nullable=True
        ),
        sa.Column("event_ts", mysql.BIGINT(), autoincrement=False, nullable=False),
        sa.PrimaryKeyConstraint("auto_id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.drop_table("materializations")
    # ### end Alembic commands ###
Add materialization model.  Revision ID: <KEY> Revises: 8817963694c9 Create Date: 2021-11-25 20:33:29.874219 # 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 ###