BS-001 Initialize BortStack foundation and project workflow
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""user table
|
||||
|
||||
Revision ID: 0f62f2706427
|
||||
Revises:
|
||||
Create Date: 2023-12-04 12:52:57.863223
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0f62f2706427"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
op.create_table(
|
||||
"user",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("email", sa.String(length=80), nullable=True),
|
||||
sa.Column("username", sa.String(length=100), nullable=True),
|
||||
sa.Column("password_hash", sa.String(length=255), nullable=True),
|
||||
sa.Column("token", sa.String(length=32), nullable=True),
|
||||
sa.Column("token_expiration", sa.DateTime(), nullable=True),
|
||||
sa.Column("refresh_token", sa.String(length=32), nullable=True),
|
||||
sa.Column("reset_password_code", sa.String(length=8), nullable=True),
|
||||
sa.Column("reset_password_expiration", sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("email"),
|
||||
)
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_refresh_token"), ["refresh_token"], unique=True
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_reset_password_code"),
|
||||
["reset_password_code"],
|
||||
unique=True,
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_token"), ["token"], unique=True
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f("ix_user_token"))
|
||||
batch_op.drop_index(batch_op.f("ix_user_reset_password_code"))
|
||||
batch_op.drop_index(batch_op.f("ix_user_refresh_token"))
|
||||
op.drop_table("user")
|
||||
@@ -0,0 +1,70 @@
|
||||
"""add account email tokens
|
||||
|
||||
Revision ID: 7a4e1b9c2d3f
|
||||
Revises: 0f62f2706427
|
||||
Create Date: 2026-08-28
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "7a4e1b9c2d3f"
|
||||
down_revision = "0f62f2706427"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("email_verified_at", sa.DateTime(), nullable=True)
|
||||
)
|
||||
batch_op.drop_index(batch_op.f("ix_user_reset_password_code"))
|
||||
batch_op.drop_column("reset_password_expiration")
|
||||
batch_op.drop_column("reset_password_code")
|
||||
|
||||
op.create_table(
|
||||
"account_token",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.Column("purpose", sa.String(length=32), nullable=False),
|
||||
sa.Column("token_hash", sa.String(length=64), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("used_at", sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["user.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("token_hash"),
|
||||
)
|
||||
with op.batch_alter_table("account_token", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_account_token_expires_at"), ["expires_at"]
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_account_token_purpose"), ["purpose"]
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_account_token_user_id"), ["user_id"]
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("account_token", schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f("ix_account_token_user_id"))
|
||||
batch_op.drop_index(batch_op.f("ix_account_token_purpose"))
|
||||
batch_op.drop_index(batch_op.f("ix_account_token_expires_at"))
|
||||
op.drop_table("account_token")
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("reset_password_code", sa.String(length=8), nullable=True)
|
||||
)
|
||||
batch_op.add_column(
|
||||
sa.Column("reset_password_expiration", sa.DateTime(), nullable=True)
|
||||
)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_reset_password_code"),
|
||||
["reset_password_code"],
|
||||
unique=True,
|
||||
)
|
||||
batch_op.drop_column("email_verified_at")
|
||||
Reference in New Issue
Block a user