extend complexity fields to text

This commit is contained in:
2025-06-20 15:10:37 +01:00
parent e043450457
commit 35753fe863
3 changed files with 58 additions and 7 deletions

View File

@@ -2,7 +2,8 @@
script_location = alembic script_location = alembic
prepend_sys_path = . prepend_sys_path = .
version_path_separator = os version_path_separator = os
sqlalchemy.url = postgresql+asyncpg://codetutor:codetutor@localhost:5432/codetutor # URL is set programmatically in alembic/env.py from environment variables
sqlalchemy.url =
[post_write_hooks] [post_write_hooks]

View File

@@ -19,9 +19,8 @@ depends_on: str | Sequence[str] | None = None
def upgrade() -> None: def upgrade() -> None:
# Create difficulty enum # Create difficulty enum using raw SQL to avoid SQLAlchemy auto-creation issues
difficulty_enum = postgresql.ENUM("easy", "medium", "hard", name="difficulty_enum") op.execute("CREATE TYPE difficulty_enum AS ENUM ('easy', 'medium', 'hard')")
difficulty_enum.create(op.get_bind())
# Create questions table # Create questions table
op.create_table( op.create_table(
@@ -31,7 +30,7 @@ def upgrade() -> None:
sa.Column("slug", sa.String(255), unique=True, nullable=False), sa.Column("slug", sa.String(255), unique=True, nullable=False),
sa.Column( sa.Column(
"difficulty", "difficulty",
sa.Enum("easy", "medium", "hard", name="difficulty_enum"), postgresql.ENUM("easy", "medium", "hard", name="difficulty_enum", create_type=False),
nullable=False, nullable=False,
), ),
sa.Column("description", sa.Text, nullable=False), sa.Column("description", sa.Text, nullable=False),
@@ -158,5 +157,4 @@ def downgrade() -> None:
op.drop_table("explanations") op.drop_table("explanations")
op.drop_table("questions") op.drop_table("questions")
difficulty_enum = postgresql.ENUM("easy", "medium", "hard", name="difficulty_enum") op.execute("DROP TYPE IF EXISTS difficulty_enum")
difficulty_enum.drop(op.get_bind())

View File

@@ -0,0 +1,52 @@
"""extend complexity fields to text
Revision ID: 11f3a598b82d
Revises: 001
Create Date: 2025-04-12 20:44:46.031680
"""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "11f3a598b82d"
down_revision: str | None = "001"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.alter_column(
"explanations",
"time_complexity",
existing_type=sa.VARCHAR(length=50),
type_=sa.Text(),
existing_nullable=False,
)
op.alter_column(
"explanations",
"space_complexity",
existing_type=sa.VARCHAR(length=50),
type_=sa.Text(),
existing_nullable=False,
)
def downgrade() -> None:
op.alter_column(
"explanations",
"space_complexity",
existing_type=sa.Text(),
type_=sa.VARCHAR(length=50),
existing_nullable=False,
)
op.alter_column(
"explanations",
"time_complexity",
existing_type=sa.Text(),
type_=sa.VARCHAR(length=50),
existing_nullable=False,
)