init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""default zeros for new user counters"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
|
||||
revision = "user_counters_defaults_old"
|
||||
down_revision = "add_ok_to_dl_stats"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _has_column(table: str, column: str, conn) -> bool:
|
||||
insp = Inspector.from_engine(conn)
|
||||
return column in [c["name"] for c in insp.get_columns(table)]
|
||||
|
||||
|
||||
def _add(column: str, coltype, default_sql: str, conn):
|
||||
if not _has_column("users", column, conn):
|
||||
op.add_column(
|
||||
"users",
|
||||
sa.Column(column, coltype, nullable=True, server_default=sa.text(default_sql)),
|
||||
)
|
||||
# Whether it was just added or already existed, be sure it is NOT NULL and no default remains
|
||||
op.alter_column("users", column, nullable=False, server_default=None)
|
||||
|
||||
|
||||
def upgrade():
|
||||
conn = op.get_bind()
|
||||
|
||||
_add("videos_downloaded", sa.Integer(), "0", conn)
|
||||
_add("mb_usage", sa.Float(), "0", conn)
|
||||
_add("level", sa.Integer(), "1", conn)
|
||||
_add("xp", sa.Integer(), "0", conn)
|
||||
_add("tier", sa.Integer(), "0", conn)
|
||||
_add("ban_status", sa.Boolean(), "false", conn)
|
||||
_add("soft_banned", sa.Boolean(), "false", conn)
|
||||
|
||||
|
||||
def downgrade():
|
||||
for col in (
|
||||
"soft_banned", "ban_status", "tier",
|
||||
"xp", "level", "mb_usage", "videos_downloaded",
|
||||
):
|
||||
op.drop_column("users", col)
|
||||
Reference in New Issue
Block a user