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
89 changes: 89 additions & 0 deletions alembic/versions/9b7b3c4d8e21_add_protocol_dependencies_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""add protocol dependencies table

Revision ID: 9b7b3c4d8e21
Revises: f3f7b0a3f1aa
Create Date: 2026-04-22 00:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '9b7b3c4d8e21'
down_revision: Union[str, None] = 'f3f7b0a3f1aa'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade():
op.create_unique_constraint(
'uq_protocols_projectId_id',
'protocols',
['projectId', 'id'],
)

op.create_table(
'protocol_dependencies',
sa.Column('projectId', sa.Integer(), nullable=False),
sa.Column('parentProtocolDbId', sa.Integer(), nullable=False),
sa.Column('childProtocolDbId', sa.Integer(), nullable=False),
sa.Column('createdAt', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.CheckConstraint('"parentProtocolDbId" <> "childProtocolDbId"', name='protocol_dependencies_no_self_loop'),
sa.ForeignKeyConstraint(['projectId'], ['projects.id'], name='protocol_dependencies_projectId_fkey', ondelete='CASCADE'),
sa.ForeignKeyConstraint(
['projectId', 'parentProtocolDbId'],
['protocols.projectId', 'protocols.id'],
name='protocol_dependencies_parentProtocolDbId_fkey',
ondelete='CASCADE',
),
sa.ForeignKeyConstraint(
['projectId', 'childProtocolDbId'],
['protocols.projectId', 'protocols.id'],
name='protocol_dependencies_childProtocolDbId_fkey',
ondelete='CASCADE',
),
sa.PrimaryKeyConstraint('projectId', 'parentProtocolDbId', 'childProtocolDbId', name='protocol_dependencies_pkey'),
)

op.create_index(
'idx_protocol_dependencies_parent',
'protocol_dependencies',
['projectId', 'parentProtocolDbId'],
unique=False,
)
op.create_index(
'idx_protocol_dependencies_child',
'protocol_dependencies',
['projectId', 'childProtocolDbId'],
unique=False,
)

op.execute(
"""
INSERT INTO protocol_dependencies (
"projectId",
"parentProtocolDbId",
"childProtocolDbId"
)
SELECT DISTINCT
child."projectId",
parent.id,
child.id
FROM protocols child
CROSS JOIN LATERAL unnest(COALESCE(child."parentIds", ARRAY[]::integer[])) AS parent_protocol_id
JOIN protocols parent
ON parent."projectId" = child."projectId"
AND parent."protocolId" = parent_protocol_id::text
WHERE parent.id <> child.id
"""
)


def downgrade():
op.drop_index('idx_protocol_dependencies_child', table_name='protocol_dependencies')
op.drop_index('idx_protocol_dependencies_parent', table_name='protocol_dependencies')
op.drop_table('protocol_dependencies')
op.drop_constraint('uq_protocols_projectId_id', 'protocols', type_='unique')
97 changes: 72 additions & 25 deletions app/backend/api/routers/project_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ def renameProtocol(
)

try:
# Basic payload validation for semantic HTTP
newName = getattr(payload, "name", None)
if not newName or not str(newName).strip():
return JSONResponse(
Expand All @@ -526,6 +525,14 @@ def renameProtocol(
)

service.renameProtocol(protocolId, str(newName).strip())
service.syncProjectGraphAfterMutation(
mapper,
projectId,
actionLabel="rename protocol",
refresh=True,
checkPid=True,
)

return {"status": 0,
"errors": [],
"workflow": []}
Expand Down Expand Up @@ -573,11 +580,12 @@ def duplicateProtocol(
"workflow": []},
)

service.duplicateProtocol(mapper, projectId, items)
result = service.duplicateProtocol(mapper, projectId, items)
# Keep 201 on success, but still return unified schema
return {"status": 0,
"errors": [],
"workflow": []}
return {"status": result['status'],
"errors": result['errors'],
"workflow": [],
"duplicated": result['duplicated']}

except HTTPException as e:
return JSONResponse(
Expand Down Expand Up @@ -659,13 +667,14 @@ def restartProtocolAll(
)

try:
errorList = service.restartProtocolAll(protocolId)
errors = [str(e) for e in (errorList or [])]

if errors:
return {"status": 1,
"errors": errors,
"workflow": []}
service.restartProtocolAll(protocolId)
service.syncProjectGraphAfterMutation(
mapper,
projectId,
actionLabel="restart protocol subtree",
refresh=True,
checkPid=True,
)

return {"status": 0,
"errors": [],
Expand Down Expand Up @@ -708,6 +717,14 @@ def continueProtocolAll(

try:
service.continueProtocolAll(mapper, projectId, protocolId, currentUser)
service.syncProjectGraphAfterMutation(
mapper,
projectId,
actionLabel="continue protocol subtree",
refresh=True,
checkPid=True,
)

return {"status": 0, "errors": [], "workflow": []}

except HTTPException as e:
Expand Down Expand Up @@ -743,6 +760,14 @@ def resetProtocolFrom(

try:
service.resetProtocolFrom(protocolId)
service.syncProjectGraphAfterMutation(
mapper,
projectId,
actionLabel="reset protocol from node",
refresh=True,
checkPid=True,
)

return {"status": 0, "errors": [], "workflow": []}

except HTTPException as e:
Expand Down Expand Up @@ -785,6 +810,14 @@ def stopProtocol(
)

service.stopProtocol(protocolIds)
service.syncProjectGraphAfterMutation(
mapper,
projectId,
actionLabel="stop protocol",
refresh=True,
checkPid=True,
)

return {"status": 0,
"errors": [],
"workflow": []}
Expand Down Expand Up @@ -2945,12 +2978,19 @@ def getProtocolThumbnail(

service.loadProjectForThumbnails(dbProj)

result = service.buildProtocolThumbnail(
protocolId=protocolId,
force=False,
size=size,
outputName=outputName,
)
if outputName:
result = service.buildProtocolOutputThumbnail(
protocolId=protocolId,
outputName=outputName,
force=False,
size=size,
)
else:
result = service.buildProtocolThumbnail(
protocolId=protocolId,
force=False,
size=size,
)

thumbPath = result.get("absolutePath")
if not thumbPath:
Expand Down Expand Up @@ -2995,12 +3035,19 @@ def rebuildProtocolThumbnail(

service.loadProjectForThumbnails(dbProj)

result = service.buildProtocolThumbnail(
protocolId=protocolId,
force=True,
size=size,
outputName=outputName,
)
if outputName:
result = service.buildProtocolOutputThumbnail(
protocolId=protocolId,
outputName=outputName,
force=True,
size=size,
)
else:
result = service.buildProtocolThumbnail(
protocolId=protocolId,
force=True,
size=size,
)

response = JSONResponse(
{
Expand Down Expand Up @@ -3050,7 +3097,7 @@ def listProjectThumbnailItems(
)

response = JSONResponse(items)
response.headers["Cache-Control"] = "private, max-age=20, stale-while-revalidate=60"
response.headers["Cache-Control"] = "private, no-store"
response.headers["Access-Control-Expose-Headers"] = "Cache-Control"
return _attachDebugHeaders(response, currentUser)

Expand Down
Loading
Loading