Fix double CREATE TYPE crashes + oversized revision id in moderation migration

0001_initial.py: restore create_type=False on the two inline ENUM column
declarations (world_visibility, asset_type) -- this task's own auto-checkpoint
had accidentally reverted the 2026-08-18 fix (PR #25) while working on an
unrelated file.

0003_add_moderation_tables_and_user_roles.py: same bug pattern, self-inflicted
this time -- added create_type=False to all 8 inline column ENUM declarations
(user_role, target_type x2, reason_category, report_status, resolution,
action_type, appeal_status). Also shortened the revision id from
0003_add_moderation_tables_and_user_roles (42 chars) to 0003_moderation_schema
(23 chars) -- alembic_version.version_num is VARCHAR(32) by default, so the
migration ran to completion and then failed writing its own bookkeeping row.

Verified against a genuinely fresh Postgres container: full chain
(0001 -> 0002 -> 0003) now runs clean, all 8 tables land.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-19 13:51:08 +00:00
parent dd56f6a22f
commit d61f08210d
2 changed files with 18 additions and 12 deletions
+3 -2
View File
@@ -69,7 +69,8 @@ def upgrade() -> None:
sa.Column(
"visibility",
postgresql.ENUM(
"public", "private", "friends_only", name="world_visibility"
"public", "private", "friends_only", name="world_visibility",
create_type=False,
),
nullable=True,
),
@@ -89,7 +90,7 @@ def upgrade() -> None:
"asset_type",
postgresql.ENUM(
"image", "audio", "video", "document", "model_3d", "other",
name="asset_type",
name="asset_type", create_type=False,
),
nullable=False,
),
@@ -1,6 +1,6 @@
"""add moderation tables and user roles
Revision ID: 0003_add_moderation_tables_and_user_roles
Revision ID: 0003_moderation_schema
Revises: 0002_add_date_of_birth_to_users
Create Date: 2025-01-02 00:00:00.000000
@@ -11,8 +11,12 @@ from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = "0003_add_moderation_tables_and_user_roles"
# revision identifiers, used by Alembic. Kept short deliberately: alembic's
# own alembic_version.version_num column is VARCHAR(32) by default, and the
# original "0003_add_moderation_tables_and_user_roles" (42 chars) exceeded
# it -- migration ran to completion and then failed writing its own version
# bookkeeping row. Verified 2026-08-19 against a genuinely fresh database.
revision: str = "0003_moderation_schema"
down_revision: Union[str, None] = "0002_add_date_of_birth_to_users"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
@@ -69,7 +73,7 @@ def upgrade() -> None:
"users",
sa.Column(
"role",
postgresql.ENUM("user", "moderator", "admin", name="user_role"),
postgresql.ENUM("user", "moderator", "admin", name="user_role", create_type=False),
nullable=False,
server_default="user",
),
@@ -86,7 +90,7 @@ def upgrade() -> None:
sa.Column(
"target_type",
postgresql.ENUM(
"user", "world", "asset", "chat_message", name="target_type"
"user", "world", "asset", "chat_message", name="target_type", create_type=False,
),
nullable=False,
),
@@ -102,6 +106,7 @@ def upgrade() -> None:
"self_harm",
"other",
name="reason_category",
create_type=False,
),
nullable=False,
),
@@ -109,7 +114,7 @@ def upgrade() -> None:
sa.Column(
"status",
postgresql.ENUM(
"open", "in_review", "resolved", "dismissed", name="report_status"
"open", "in_review", "resolved", "dismissed", name="report_status", create_type=False,
),
nullable=False,
server_default="open",
@@ -118,7 +123,7 @@ def upgrade() -> None:
sa.Column(
"resolution",
postgresql.ENUM(
"action_taken", "dismissed", "no_violation", name="resolution"
"action_taken", "dismissed", "no_violation", name="resolution", create_type=False,
),
nullable=True,
),
@@ -154,7 +159,7 @@ def upgrade() -> None:
sa.Column(
"target_type",
postgresql.ENUM(
"user", "world", "asset", "chat_message", name="target_type"
"user", "world", "asset", "chat_message", name="target_type", create_type=False,
),
nullable=False,
),
@@ -163,7 +168,7 @@ def upgrade() -> None:
"action",
postgresql.ENUM(
"warn", "suspend", "ban", "restrict", "remove", "restore",
name="action_type",
name="action_type", create_type=False,
),
nullable=False,
),
@@ -209,7 +214,7 @@ def upgrade() -> None:
sa.Column(
"status",
postgresql.ENUM(
"pending", "approved", "rejected", name="appeal_status"
"pending", "approved", "rejected", name="appeal_status", create_type=False,
),
nullable=False,
server_default="pending",