pyproger/migrations/versions/8c415e462cb3_initial_migrat...

133 lines
4.5 KiB
Python

"""initial_migration
Revision ID: 8c415e462cb3
Revises:
Create Date: 2023-09-22 12:19:22.923813
"""
import flask_security
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "8c415e462cb3"
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"role",
sa.Column("name", sa.String(length=80), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("description", sa.String(length=255), nullable=True),
sa.Column("permissions", flask_security.datastore.AsaList(), nullable=True),
sa.Column(
"update_datetime",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("name"),
)
op.create_table(
"tag",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("tag", sa.String(length=20), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"user",
sa.Column("first_name", sa.String(length=255), nullable=True),
sa.Column("last_name", sa.String(length=255), nullable=True),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("email", sa.String(length=255), nullable=False),
sa.Column("username", sa.String(length=255), nullable=True),
sa.Column("password", sa.String(length=255), nullable=False),
sa.Column("active", sa.Boolean(), nullable=False),
sa.Column("fs_uniquifier", sa.String(length=64), nullable=False),
sa.Column("confirmed_at", sa.DateTime(), nullable=True),
sa.Column("last_login_at", sa.DateTime(), nullable=True),
sa.Column("current_login_at", sa.DateTime(), nullable=True),
sa.Column("last_login_ip", sa.String(length=64), nullable=True),
sa.Column("current_login_ip", sa.String(length=64), nullable=True),
sa.Column("login_count", sa.Integer(), nullable=True),
sa.Column("tf_primary_method", sa.String(length=64), nullable=True),
sa.Column("tf_totp_secret", sa.String(length=255), nullable=True),
sa.Column("tf_phone_number", sa.String(length=128), nullable=True),
sa.Column(
"create_datetime",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"update_datetime",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("email"),
sa.UniqueConstraint("fs_uniquifier"),
)
op.create_table(
"post",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("author", sa.Integer(), nullable=True),
sa.Column("slug", sa.String(length=100), nullable=False),
sa.Column("title", sa.Text(), nullable=False),
sa.Column("description", sa.Text(), nullable=False),
sa.Column("published", sa.Boolean(), nullable=True),
sa.Column("create_datetime", sa.DateTime(), nullable=True),
sa.Column("update_datetime", sa.DateTime(), nullable=True),
sa.Column("text", sa.Text(), nullable=True),
sa.ForeignKeyConstraint(
["author"],
["user.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("id"),
)
op.create_table(
"roles_users",
sa.Column("user_id", sa.Integer(), nullable=True),
sa.Column("role_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["role_id"],
["role.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["user.id"],
),
)
op.create_table(
"tag_post",
sa.Column("tag_id", sa.Integer(), nullable=True),
sa.Column("post_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["post_id"],
["post.id"],
),
sa.ForeignKeyConstraint(
["tag_id"],
["tag.id"],
),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("tag_post")
op.drop_table("roles_users")
op.drop_table("post")
op.drop_table("user")
op.drop_table("tag")
op.drop_table("role")
# ### end Alembic commands ###