From 6808bd62c2f34391208c16d8c90f79f344776283 Mon Sep 17 00:00:00 2001 From: Urvish Date: Mon, 16 Nov 2026 12:34:57 +0530 Subject: [PATCH] fix(module-builder): widen category, disease, and pattern code columns to VARCHAR(128) Expand category_code, disease_code, and pattern_code from VARCHAR(64) to VARCHAR(128) in content.builder_* tables and Alembic migration 0005 to support descriptive TCM clinical pattern slugs without truncation errors. --- alembic/versions/0005_builder_modules_table.py | 8 ++++++++ app/db/models/content.py | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/alembic/versions/0005_builder_modules_table.py b/alembic/versions/0005_builder_modules_table.py index 52e7149..cfe7b08 100644 --- a/alembic/versions/0005_builder_modules_table.py +++ b/alembic/versions/0005_builder_modules_table.py @@ -154,6 +154,14 @@ def upgrade() -> None: onupdate="CASCADE", ) + # Expand code columns to 128 characters to safely handle long clinical pattern codes + op.alter_column("builder_categories", "category_code", type_=sa.String(128), schema=CONTENT_SCHEMA) + op.alter_column("builder_diseases", "category_code", type_=sa.String(128), schema=CONTENT_SCHEMA) + op.alter_column("builder_diseases", "disease_code", type_=sa.String(128), schema=CONTENT_SCHEMA) + op.alter_column("builder_patterns", "category_code", type_=sa.String(128), schema=CONTENT_SCHEMA) + op.alter_column("builder_patterns", "disease_code", type_=sa.String(128), schema=CONTENT_SCHEMA) + op.alter_column("builder_patterns", "pattern_code", type_=sa.String(128), schema=CONTENT_SCHEMA) + def downgrade() -> None: bind = op.get_bind() diff --git a/app/db/models/content.py b/app/db/models/content.py index f5998bc..66ac8ca 100644 --- a/app/db/models/content.py +++ b/app/db/models/content.py @@ -948,7 +948,7 @@ class BuilderCategory(Base): PGUUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()") ) module_code: Mapped[str] = mapped_column(String(32), nullable=False) - category_code: Mapped[str] = mapped_column(String(64), nullable=False) + category_code: Mapped[str] = mapped_column(String(128), nullable=False) name: Mapped[str] = mapped_column(String(255), nullable=False) overview: Mapped[str | None] = mapped_column(Text) sort_order: Mapped[int] = mapped_column(Integer, nullable=False, server_default=text("0")) @@ -986,8 +986,8 @@ class BuilderDisease(Base): PGUUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()") ) module_code: Mapped[str] = mapped_column(String(32), nullable=False) - category_code: Mapped[str] = mapped_column(String(64), nullable=False) - disease_code: Mapped[str] = mapped_column(String(64), nullable=False) + category_code: Mapped[str] = mapped_column(String(128), nullable=False) + disease_code: Mapped[str] = mapped_column(String(128), nullable=False) name: Mapped[str] = mapped_column(String(255), nullable=False) overview: Mapped[str | None] = mapped_column(Text) sort_order: Mapped[int] = mapped_column(Integer, nullable=False, server_default=text("0")) @@ -1025,9 +1025,9 @@ class BuilderPattern(Base): PGUUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()") ) module_code: Mapped[str] = mapped_column(String(32), nullable=False) - category_code: Mapped[str] = mapped_column(String(64), nullable=False) - disease_code: Mapped[str] = mapped_column(String(64), nullable=False) - pattern_code: Mapped[str] = mapped_column(String(64), nullable=False) + category_code: Mapped[str] = mapped_column(String(128), nullable=False) + disease_code: Mapped[str] = mapped_column(String(128), nullable=False) + pattern_code: Mapped[str] = mapped_column(String(128), nullable=False) name: Mapped[str] = mapped_column(String(255), nullable=False) description: Mapped[str | None] = mapped_column(Text) clinical_data: Mapped[dict[str, Any]] = mapped_column(