Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Import app configuration and models
from app.core.config import settings
from app.db.base import Base
from app.db.mysql_loop_items_schema import normalize_mysql_loop_items_schema
from app.db.timezone import MYSQL_SESSION_TIMEZONE_OFFSET

# Import all models to ensure they are registered with SQLAlchemy
Expand Down Expand Up @@ -138,6 +139,7 @@ def _initialize_fresh_database(connection) -> None:
# This is cross-database compatible (works for both MySQL and SQLite)
logger.info("Creating all tables using SQLAlchemy metadata...")
Base.metadata.create_all(bind=connection, checkfirst=True)
normalize_mysql_loop_items_schema(connection)
logger.info("All tables created successfully")

# Step 2: Create alembic_version table and stamp to head
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Align MySQL loop items with the production sentinel schema.

Revision ID: c0d1e2f3a4b5
Revises: b9c0d1e2f3a4
Create Date: 2026-08-04
"""

from typing import Sequence, Union

from alembic import op
from app.db.mysql_loop_items_schema import (
normalize_mysql_loop_items_schema,
restore_nullable_mysql_loop_items_schema,
)

revision: str = "c0d1e2f3a4b5"
down_revision: Union[str, Sequence[str], None] = "b9c0d1e2f3a4"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Use sentinel values and generated unique projections on MySQL."""

normalize_mysql_loop_items_schema(op.get_bind())


def downgrade() -> None:
"""Restore nullable columns, direct unique indexes, and foreign keys."""

restore_nullable_mysql_loop_items_schema(op.get_bind())
Loading
Loading