Files

89 lines
3.2 KiB
Python

"""Initial schema baseline.
Represents the full current schema as of 2026-03-14. This migration creates
all tables and indexes from scratch. It is intended as a *baseline* — it
records the existing state so that future migrations can be auto-generated
with ``alembic revision --autogenerate``.
On a fresh database, ``alembic upgrade head`` will apply this migration and
produce the full schema. On an existing database that was bootstrapped by the
legacy ``init_db()`` function, you should stamp the current revision as applied
without re-running DDL::
alembic -c backend/alembic.ini stamp 0001
Revision ID: 0001
Revises:
Create Date: 2026-03-14
"""
from __future__ import annotations
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "0001"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ------------------------------------------------------------------
# jobs table
# ------------------------------------------------------------------
op.create_table(
"jobs",
sa.Column("id", sa.String, primary_key=True),
sa.Column("job_type", sa.String, nullable=False),
sa.Column("status", sa.String, server_default="queued"),
sa.Column("progress", sa.String, server_default=""),
sa.Column("error", sa.Text, server_default=""),
sa.Column("files", sa.JSON),
sa.Column("result", sa.JSON),
sa.Column("created_at", sa.DateTime),
sa.Column("updated_at", sa.DateTime),
)
# ------------------------------------------------------------------
# projects table
# ------------------------------------------------------------------
op.create_table(
"projects",
sa.Column("id", sa.String, primary_key=True),
sa.Column("name", sa.String, nullable=False),
sa.Column("tab_label", sa.String, server_default=""),
sa.Column("created_at", sa.DateTime),
sa.Column("sep_job_id", sa.String, nullable=False),
sa.Column("trans_jobs", sa.JSON),
sa.Column("abc_jobs", sa.JSON),
sa.Column("lrc_jobs", sa.JSON),
sa.Column("mix_job_id", sa.String, nullable=True),
)
# ------------------------------------------------------------------
# project_stem_job_links table (Phase 5 normalization)
# ------------------------------------------------------------------
op.create_table(
"project_stem_job_links",
sa.Column("id", sa.String, primary_key=True),
sa.Column("project_id", sa.String, nullable=False, index=True),
sa.Column("stage", sa.String, nullable=False, index=True),
sa.Column("stem_name", sa.String, nullable=False),
sa.Column("job_id", sa.String, nullable=False, index=True),
sa.Column("created_at", sa.DateTime),
sa.Column("updated_at", sa.DateTime),
)
op.create_unique_constraint(
"uq_project_stage_stem",
"project_stem_job_links",
["project_id", "stage", "stem_name"],
)
def downgrade() -> None:
op.drop_table("project_stem_job_links")
op.drop_table("projects")
op.drop_table("jobs")