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
13 changes: 13 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ dev-down:
open-ui:
open http://localhost:8080

# === Code Quality ===

# Lint all code (server + web)
lint:
cd server && just lint
cd web && pnpm lint

# === Individual Service Development ===

# Run server independently (requires database)
Expand All @@ -76,6 +83,12 @@ web-build:
web-lint:
cd web && pnpm lint

# === Seed ===

# Seed the database with sample data (run while dev is up)
seed:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml exec server /app/.venv/bin/python /app/scripts/seed.py

# === Database ===

# Start only the database
Expand Down
2 changes: 1 addition & 1 deletion deploy/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
OSA_LOGGING__LEVEL: ${LOG_LEVEL:-DEBUG}
WATCHFILES_FORCE_POLLING: "true"
entrypoint: []
command: ["sh", "-c", "/app/.venv/bin/alembic upgrade head && /app/.venv/bin/uvicorn osa.application.api.rest.app:app --host 0.0.0.0 --port 8000 --reload"]
command: ["sh", "-c", "/app/.venv/bin/alembic upgrade head && /app/.venv/bin/python /app/scripts/seed.py && /app/.venv/bin/uvicorn osa.application.api.rest.app:app --host 0.0.0.0 --port 8000 --reload"]
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:8000/api/v1/health"]
interval: 10s
Expand Down
108 changes: 108 additions & 0 deletions server/migrations/versions/add_deposition_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""add_deposition_tables

Add ontologies, ontology_terms, schemas, conventions tables.
Alter depositions: add convention_srn, drop provenance.

Revision ID: add_deposition_tables
Revises: add_authorization
Create Date: 2026-02-08

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "add_deposition_tables"
down_revision: Union[str, Sequence[str], None] = "add_authorization"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Add semantics/convention tables and update depositions."""
# ONTOLOGIES
op.create_table(
"ontologies",
sa.Column("srn", sa.String(), nullable=False),
sa.Column("title", sa.String(255), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint("srn"),
)

# ONTOLOGY TERMS
op.create_table(
"ontology_terms",
sa.Column("id", sa.String(), nullable=False),
sa.Column("ontology_srn", sa.String(), nullable=False),
sa.Column("term_id", sa.String(255), nullable=False),
sa.Column("label", sa.String(255), nullable=False),
sa.Column("synonyms", sa.JSON(), nullable=False),
sa.Column("parent_ids", sa.JSON(), nullable=False),
sa.Column("definition", sa.Text(), nullable=True),
sa.Column("deprecated", sa.Boolean(), nullable=False, server_default="false"),
sa.PrimaryKeyConstraint("id"),
sa.ForeignKeyConstraint(
["ontology_srn"],
["ontologies.srn"],
ondelete="CASCADE",
),
sa.UniqueConstraint("ontology_srn", "term_id", name="uq_ontology_term"),
)
op.create_index("idx_ontology_terms_ontology_srn", "ontology_terms", ["ontology_srn"])

# SCHEMAS
op.create_table(
"schemas",
sa.Column("srn", sa.String(), nullable=False),
sa.Column("title", sa.String(255), nullable=False),
sa.Column("fields", sa.JSON(), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint("srn"),
)

# CONVENTIONS
op.create_table(
"conventions",
sa.Column("srn", sa.String(), nullable=False),
sa.Column("title", sa.String(255), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("schema_srn", sa.String(), nullable=False),
sa.Column("file_requirements", sa.JSON(), nullable=False),
sa.Column("validator_refs", sa.JSON(), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint("srn"),
)

# ALTER DEPOSITIONS: add convention_srn, drop provenance
op.add_column(
"depositions",
sa.Column("convention_srn", sa.String(), nullable=False),
)
Comment on lines +81 to +84
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration/table definition nullability mismatch

The migration adds convention_srn as nullable=True, but the SQLAlchemy table definition in tables.py:29 declares it as nullable=False, and the domain model requires convention_srn as a mandatory field on Deposition. This mismatch means:

  1. The migration will create the column as nullable in the database
  2. SQLAlchemy's table metadata believes it's non-nullable
  3. Any existing deposition rows would need a convention_srn value to satisfy the constraint

If this runs against a database with existing depositions, the ALTER TABLE ADD COLUMN with nullable=True will succeed, but those rows will have NULL for convention_srn, which will cause errors when the ORM tries to load them. The migration should either set a server_default or include a data migration step for existing rows, then alter to NOT NULL.

Suggested change
op.add_column(
"depositions",
sa.Column("convention_srn", sa.String(), nullable=True),
)
op.add_column(
"depositions",
sa.Column("convention_srn", sa.String(), nullable=False, server_default=""),
)

op.drop_column("depositions", "provenance")


def downgrade() -> None:
"""Reverse: restore depositions, drop new tables."""
# DEPOSITIONS: re-add provenance, drop convention_srn
op.add_column(
"depositions",
sa.Column("provenance", sa.JSON(), nullable=False, server_default="{}"),
)
op.drop_column("depositions", "convention_srn")

# CONVENTIONS
op.drop_table("conventions")

# SCHEMAS
op.drop_table("schemas")

# ONTOLOGY TERMS
op.drop_index("idx_ontology_terms_ontology_srn", table_name="ontology_terms")
op.drop_table("ontology_terms")

# ONTOLOGIES
op.drop_table("ontologies")
82 changes: 82 additions & 0 deletions server/ontologies/biological-sex.obographs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"graphs": [
{
"id": "http://purl.obolibrary.org/obo/osa/biological-sex.owl",
"lbl": "Biological Sex",
"meta": {
"version": "1.0.0",
"definition": {
"val": "An ontology of biological sex categories for scientific data annotation."
}
},
"nodes": [
{
"id": "OSAO:0000001",
"lbl": "biological sex",
"type": "CLASS",
"meta": {
"definition": {
"val": "The biological sex of an organism, determined by chromosomal, gonadal, and anatomical characteristics."
}
}
},
{
"id": "OSAO:0000002",
"lbl": "female",
"type": "CLASS",
"meta": {
"definition": {
"val": "An organism that produces ova or has XX sex chromosomes."
},
"synonyms": [
{ "val": "F" }
]
}
},
{
"id": "OSAO:0000003",
"lbl": "male",
"type": "CLASS",
"meta": {
"definition": {
"val": "An organism that produces spermatozoa or has XY sex chromosomes."
},
"synonyms": [
{ "val": "M" }
]
}
},
{
"id": "OSAO:0000004",
"lbl": "intersex",
"type": "CLASS",
"meta": {
"definition": {
"val": "An organism with sex characteristics that do not fit typical definitions of male or female."
}
}
},
{
"id": "OSAO:0000005",
"lbl": "unknown sex",
"type": "CLASS",
"meta": {
"definition": {
"val": "The biological sex of the organism has not been determined."
},
"synonyms": [
{ "val": "undetermined" },
{ "val": "not recorded" }
]
}
}
],
"edges": [
{ "sub": "OSAO:0000002", "pred": "is_a", "obj": "OSAO:0000001" },
{ "sub": "OSAO:0000003", "pred": "is_a", "obj": "OSAO:0000001" },
{ "sub": "OSAO:0000004", "pred": "is_a", "obj": "OSAO:0000001" },
{ "sub": "OSAO:0000005", "pred": "is_a", "obj": "OSAO:0000001" }
]
}
]
}
122 changes: 122 additions & 0 deletions server/ontologies/license.obographs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"graphs": [
{
"id": "http://purl.obolibrary.org/obo/osa/license.owl",
"lbl": "License",
"meta": {
"version": "1.0.0",
"definition": {
"val": "An ontology of common open-access and open-source license types for scientific data."
}
},
"nodes": [
{
"id": "OSAO:1000001",
"lbl": "license",
"type": "CLASS",
"meta": {
"definition": {
"val": "A legal instrument governing the use and redistribution of a creative work or dataset."
}
}
},
{
"id": "OSAO:1000002",
"lbl": "CC0 1.0",
"type": "CLASS",
"meta": {
"definition": {
"val": "Creative Commons Zero v1.0 Universal — public domain dedication."
},
"synonyms": [
{ "val": "CC0" },
{ "val": "Public Domain" }
],
"xrefs": [
{ "val": "SPDX:CC0-1.0" }
]
}
},
{
"id": "OSAO:1000003",
"lbl": "CC BY 4.0",
"type": "CLASS",
"meta": {
"definition": {
"val": "Creative Commons Attribution 4.0 International — requires attribution."
},
"synonyms": [
{ "val": "CC-BY" }
],
"xrefs": [
{ "val": "SPDX:CC-BY-4.0" }
]
}
},
{
"id": "OSAO:1000004",
"lbl": "CC BY-SA 4.0",
"type": "CLASS",
"meta": {
"definition": {
"val": "Creative Commons Attribution-ShareAlike 4.0 International — requires attribution and share-alike."
},
"xrefs": [
{ "val": "SPDX:CC-BY-SA-4.0" }
]
}
},
{
"id": "OSAO:1000005",
"lbl": "CC BY-NC 4.0",
"type": "CLASS",
"meta": {
"definition": {
"val": "Creative Commons Attribution-NonCommercial 4.0 International — requires attribution, non-commercial use."
},
"xrefs": [
{ "val": "SPDX:CC-BY-NC-4.0" }
]
}
},
{
"id": "OSAO:1000006",
"lbl": "CC BY-NC-SA 4.0",
"type": "CLASS",
"meta": {
"definition": {
"val": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International."
},
"xrefs": [
{ "val": "SPDX:CC-BY-NC-SA-4.0" }
]
}
},
{
"id": "OSAO:1000007",
"lbl": "MIT License",
"type": "CLASS",
"meta": {
"definition": {
"val": "A permissive open-source license with minimal restrictions on reuse."
},
"synonyms": [
{ "val": "MIT" }
],
"xrefs": [
{ "val": "SPDX:MIT" }
]
}
}
],
"edges": [
{ "sub": "OSAO:1000002", "pred": "is_a", "obj": "OSAO:1000001" },
{ "sub": "OSAO:1000003", "pred": "is_a", "obj": "OSAO:1000001" },
{ "sub": "OSAO:1000004", "pred": "is_a", "obj": "OSAO:1000001" },
{ "sub": "OSAO:1000005", "pred": "is_a", "obj": "OSAO:1000001" },
{ "sub": "OSAO:1000006", "pred": "is_a", "obj": "OSAO:1000001" },
{ "sub": "OSAO:1000007", "pred": "is_a", "obj": "OSAO:1000001" }
]
}
]
}
8 changes: 8 additions & 0 deletions server/osa/application/api/rest/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
from osa.application.api.v1.routes import (
admin,
auth,
conventions,
depositions,
events,
health,
ontologies,
records,
schemas,
search,
stats,
validation,
Expand Down Expand Up @@ -78,6 +82,10 @@ def create_app() -> FastAPI:
app_instance.include_router(records.router, prefix="/api/v1")
app_instance.include_router(search.router, prefix="/api/v1")
app_instance.include_router(stats.router, prefix="/api/v1")
app_instance.include_router(ontologies.router, prefix="/api/v1")
app_instance.include_router(schemas.router, prefix="/api/v1")
app_instance.include_router(conventions.router, prefix="/api/v1")
app_instance.include_router(depositions.router, prefix="/api/v1")
app_instance.include_router(validation.router, prefix="/api/v1")

# Global OSA error handler - maps domain and infrastructure errors to HTTP responses
Expand Down
Loading
Loading