Finalize database deployment readiness
This commit is contained in:
7 files changed
+662
-33
No files matched your search
@@ -6,9 +6,6 @@ Create Date: 2026-06-23
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
import string
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
@@ -18,28 +15,10 @@ down_revision = "0001_public_foundation"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
ALPHABET = string.ascii_lowercase + string.digits
|
||||
|
||||
|
||||
def _key(existing: set[str], length: int = 6) -> str:
|
||||
while True:
|
||||
value = "".join(secrets.choice(ALPHABET) for _ in range(length))
|
||||
if value not in existing:
|
||||
existing.add(value)
|
||||
return value
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("leagues", sa.Column("public_key", sa.String(length=12), nullable=True))
|
||||
|
||||
bind = op.get_bind()
|
||||
rows = bind.execute(sa.text("SELECT id FROM leagues")).mappings().all()
|
||||
existing: set[str] = set()
|
||||
for row in rows:
|
||||
bind.execute(
|
||||
sa.text("UPDATE leagues SET public_key = :public_key WHERE id = :id"),
|
||||
{"public_key": _key(existing), "id": row["id"]},
|
||||
)
|
||||
op.execute("UPDATE leagues SET public_key = substr(replace(id, '-', ''), 1, 12) WHERE public_key IS NULL")
|
||||
|
||||
with op.batch_alter_table("leagues") as batch_op:
|
||||
batch_op.alter_column("public_key", existing_type=sa.String(length=12), nullable=False)
|
||||
|
||||
@@ -6,7 +6,7 @@ Create Date: 2026-06-28
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
from alembic import context, op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
@@ -17,6 +17,18 @@ depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if context.is_offline_mode():
|
||||
op.add_column(
|
||||
"users",
|
||||
sa.Column(
|
||||
"is_site_admin",
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.false(),
|
||||
),
|
||||
)
|
||||
return
|
||||
|
||||
columns = {column["name"] for column in sa.inspect(op.get_bind()).get_columns("users")}
|
||||
if "is_site_admin" not in columns:
|
||||
op.add_column(
|
||||
@@ -31,6 +43,10 @@ def upgrade() -> None:
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if context.is_offline_mode():
|
||||
op.drop_column("users", "is_site_admin")
|
||||
return
|
||||
|
||||
columns = {column["name"] for column in sa.inspect(op.get_bind()).get_columns("users")}
|
||||
if "is_site_admin" in columns:
|
||||
op.drop_column("users", "is_site_admin")
|
||||
Reference in new issue
Block a user