Files
s1ne/backend/alembic/versions/20250521_remove_xp_system.py
2026-03-29 23:50:49 -05:00

56 lines
2.0 KiB
Python

"""Drop XP / tier related columns (+data) if they exist
Revision ID: 20250521_remove_xp_system
Revises: 05d6342e2105
Create Date: 2025-05-21
"""
from alembic import op
import sqlalchemy as sa
revision = "20250521_remove_xp_system"
down_revision = "05d6342e2105"
branch_labels = None
depends_on = None
# added "data" here ↓↓↓
XP_COLUMNS = (
"videos_downloaded",
"mb_usage",
"level",
"xp",
"tier",
"admin",
"vip_badge",
"bonus_active_until",
"score",
"data", # ← drop the NOT-NULL JSON/profile blob
)
def upgrade() -> None:
conn = op.get_bind()
existing = {c["name"] for c in sa.inspect(conn).get_columns("users")}
with op.batch_alter_table("users") as batch:
for col in XP_COLUMNS:
if col in existing:
batch.drop_column(col)
def downgrade() -> None:
conn = op.get_bind()
existing = {c["name"] for c in sa.inspect(conn).get_columns("users")}
with op.batch_alter_table("users") as batch:
# Only re-add if missing; "data" comes back as JSON/Text and NULL-able
add = lambda name, *args, **kw: (
batch.add_column(sa.Column(name, *args, **kw))
if name not in existing else None
)
add("videos_downloaded", sa.Integer(), server_default="0", nullable=False)
add("mb_usage", sa.Float(), server_default="0", nullable=False)
add("level", sa.Integer(), server_default="1", nullable=False)
add("xp", sa.Integer(), server_default="0", nullable=False)
add("tier", sa.Text(), server_default="Online")
add("admin", sa.Boolean(), server_default="false", nullable=False)
add("vip_badge", sa.Text())
add("bonus_active_until", sa.DateTime(timezone=True))
add("score", sa.Float(), server_default="0")
add("data", sa.JSON(), server_default="{}") # <<<