Skip to content
Merged
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
5 changes: 2 additions & 3 deletions alembic/versions/0010_add_taxonomy_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import sqlalchemy as sa

from alembic import op

revision = "0010_add_taxonomy_info"
Expand All @@ -30,9 +31,7 @@ def upgrade() -> None:
sa.Column("augustus_dataset_name", sa.Text(), nullable=True),
sa.Column("genetic_code_id", sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint("taxon_id"),
sa.ForeignKeyConstraint(
["taxon_id"], ["organism.taxon_id"], ondelete="CASCADE"
),
sa.ForeignKeyConstraint(["taxon_id"], ["organism.taxon_id"], ondelete="CASCADE"),
)

# 2. Migrate existing augustus_dataset_name values from organism into taxonomy_info
Expand Down
153 changes: 153 additions & 0 deletions alembic/versions/0011_assembly_first_and_stages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
"""Assembly-first manifest flow: nullable fields, status, and stage reporting tables.

Revision ID: 0011_assembly_first_and_stages
Revises: 0010_add_taxonomy_info
Create Date: 2026-05-05
"""

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSONB, UUID

from alembic import op

revision = "0011_assembly_first_and_stages"
down_revision = "0010_add_taxonomy_info"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ── 1. Make late-known assembly fields nullable ──────────────────────────
op.alter_column("assembly", "assembly_name", existing_type=sa.Text(), nullable=True)
op.alter_column("assembly", "coverage", existing_type=sa.Float(), nullable=True)
op.alter_column("assembly", "program", existing_type=sa.Text(), nullable=True)

# ── 2. Add lifecycle status to assembly ───────────────────────────────────
op.add_column(
"assembly",
sa.Column(
"status",
sa.Text(),
nullable=False,
server_default="requested",
),
)
op.create_check_constraint(
"ck_assembly_status",
"assembly",
"status IN ('requested', 'running', 'curating', 'completed', 'failed', 'cancelled')",
)

# ── 3. assembly_stage catalog ─────────────────────────────────────────────
op.create_table(
"assembly_stage",
sa.Column("name", sa.Text(), primary_key=True),
sa.Column("category", sa.Text(), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.CheckConstraint("category IN ('pipeline', 'manual')", name="ck_assembly_stage_category"),
)

op.execute(
"""
INSERT INTO assembly_stage (name, category) VALUES
('genomeassembly', 'pipeline'),
('ascc', 'pipeline'),
('treeval', 'pipeline'),
('curation-pretext', 'pipeline'),
('manual-curation', 'manual')
"""
)

# ── 4. assembly_stage_run ─────────────────────────────────────────────────
op.create_table(
"assembly_stage_run",
sa.Column(
"id",
UUID(as_uuid=True),
primary_key=True,
server_default=sa.text("uuid_generate_v4()"),
),
sa.Column(
"assembly_id",
UUID(as_uuid=True),
sa.ForeignKey("assembly.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column(
"stage_name",
sa.Text(),
sa.ForeignKey("assembly_stage.name"),
nullable=False,
),
sa.Column("status", sa.Text(), nullable=False),
sa.Column("external_run_id", sa.Text(), nullable=True),
sa.Column("attempt", sa.Integer(), nullable=False, server_default="1"),
sa.Column("stats", JSONB(), nullable=False, server_default="{}"),
sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.func.now(),
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.func.now(),
),
sa.CheckConstraint(
"status IN ('running', 'succeeded', 'failed', 'cancelled')",
name="ck_assembly_stage_run_status",
),
sa.UniqueConstraint(
"assembly_id", "stage_name", "attempt", name="uq_stage_run_assembly_stage_attempt"
),
)
op.create_index("ix_assembly_stage_run_assembly_id", "assembly_stage_run", ["assembly_id"])

# ── 5. assembly_stage_run_file ────────────────────────────────────────────
op.create_table(
"assembly_stage_run_file",
sa.Column(
"id",
UUID(as_uuid=True),
primary_key=True,
server_default=sa.text("uuid_generate_v4()"),
),
sa.Column(
"assembly_stage_run_id",
UUID(as_uuid=True),
sa.ForeignKey("assembly_stage_run.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("storage_type", sa.Text(), nullable=False),
sa.Column("storage_uri", sa.Text(), nullable=False),
sa.Column("storage_details", JSONB(), nullable=False, server_default="{}"),
sa.Column("sha256sum", sa.Text(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.func.now(),
),
)
op.create_index(
"ix_assembly_stage_run_file_run_id",
"assembly_stage_run_file",
["assembly_stage_run_id"],
)


def downgrade() -> None:
op.drop_table("assembly_stage_run_file")
op.drop_table("assembly_stage_run")
op.drop_table("assembly_stage")

op.drop_constraint("ck_assembly_status", "assembly", type_="check")
op.drop_column("assembly", "status")

op.alter_column("assembly", "program", existing_type=sa.Text(), nullable=False)
op.alter_column("assembly", "coverage", existing_type=sa.Float(), nullable=False)
op.alter_column("assembly", "assembly_name", existing_type=sa.Text(), nullable=False)
60 changes: 60 additions & 0 deletions alembic/versions/0012_assembly_manifest_columns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Add specimen sample IDs and manifest JSON to assembly.

Revision ID: 0012_assembly_manifest_columns
Revises: 0011_assembly_first_and_stages
Create Date: 2026-05-08

Adds three nullable columns to the assembly table:
- long_read_specimen_sample_id: the specimen sample used for long reads (PacBio / ONT)
- hic_specimen_sample_id: the specimen sample used for Hi-C reads (optional)
- manifest_json: persisted JSON manifest generated at intent time

All columns are nullable so existing rows are unaffected.
"""

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSONB, UUID

from alembic import op

revision = "0012_assembly_manifest_columns"
down_revision = "0011_assembly_first_and_stages"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"assembly",
sa.Column(
"long_read_specimen_sample_id",
UUID(as_uuid=True),
sa.ForeignKey("sample.id"),
nullable=True,
),
)
op.add_column(
"assembly",
sa.Column(
"hic_specimen_sample_id",
UUID(as_uuid=True),
sa.ForeignKey("sample.id"),
nullable=True,
),
)
op.add_column(
"assembly",
sa.Column("manifest_json", JSONB(), nullable=True),
)
op.create_index(
"idx_assembly_intent_version_key",
"assembly",
["taxon_id", "long_read_specimen_sample_id"],
)


def downgrade() -> None:
op.drop_index("idx_assembly_intent_version_key", table_name="assembly")
op.drop_column("assembly", "manifest_json")
op.drop_column("assembly", "hic_specimen_sample_id")
op.drop_column("assembly", "long_read_specimen_sample_id")
4 changes: 1 addition & 3 deletions app/api/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
api_router.include_router(reads.router, prefix="/reads", tags=["reads"])
api_router.include_router(qc_reads.router, prefix="/qc-reads", tags=["qc-reads"])
api_router.include_router(genome_notes.router, prefix="/genome-notes", tags=["genome-notes"])
api_router.include_router(
taxonomy_info.router, prefix="/taxonomy-info", tags=["taxonomy-info"]
)
api_router.include_router(taxonomy_info.router, prefix="/taxonomy-info", tags=["taxonomy-info"])

# XML export endpoints
api_router.include_router(xml_export.router, prefix="/xml-export", tags=["xml-export"])
Expand Down
Loading
Loading