Skip to content
Snippets Groups Projects
5521b5759004_create_user_and_bucket_table.py 1.52 KiB
"""Create user and bucket table

Revision ID: 5521b5759004
Revises:
Create Date: 2022-05-03 14:01:22.154984

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

from alembic import op

# revision identifiers, used by Alembic.
revision = "5521b5759004"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "user",
        sa.Column("uid", sa.String(length=64), nullable=False),
        sa.Column("name", sa.String(length=256), nullable=False),
        sa.PrimaryKeyConstraint("uid"),
    )
    op.create_index(op.f("ix_user_uid"), "user", ["uid"], unique=True)
    op.create_table(
        "bucket",
        sa.Column("name", sa.String(length=63), nullable=False),
        sa.Column("description", mysql.TEXT(), nullable=False),
        sa.Column("public", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("owner_id", sa.String(length=64), nullable=True),
        sa.ForeignKeyConstraint(
            ["owner_id"],
            ["user.uid"],
        ),
        sa.PrimaryKeyConstraint("name"),
    )
    op.create_index(op.f("ix_bucket_name"), "bucket", ["name"], unique=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_bucket_name"), table_name="bucket")
    op.drop_table("bucket")
    op.drop_index(op.f("ix_user_uid"), table_name="user")
    op.drop_table("user")
    # ### end Alembic commands ###