Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Jan 3, 2026

Summary

Can deploy, undeploy, and activate specific workflows. Extracted into helpers to use between actual Sim platform and admin routes.

Type of Change

  • New feature

Testing

Tested manually curling admin routes

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 3, 2026 1:53am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 3, 2026

Greptile Summary

Extracted deployment logic into reusable helper functions and added new admin API routes for managing workflow deployments. The refactoring eliminates code duplication by moving undeployWorkflow, activateWorkflowVersion, and listWorkflowVersions into lib/workflows/persistence/utils.ts.

Key Changes:

  • Added three new admin API endpoints: deploy/undeploy workflows, activate specific versions, and list deployment versions
  • Refactored existing user-facing routes to use the extracted helper functions
  • Created DbOrTx type to support functions that work with both database instances and transactions
  • Added special handling for admin-api actor ID to display as "Admin" in deployment history
  • All new routes include proper authentication, validation, error handling, and logging

Confidence Score: 5/5

  • Safe to merge with minimal risk
  • Clean refactoring with excellent code organization - extracted helpers eliminate duplication while preserving exact behavior, all routes have proper validation and error handling, and the change follows established patterns
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/workflows/persistence/utils.ts Added three new exported helper functions (undeployWorkflow, activateWorkflowVersion, listWorkflowVersions) to enable code reuse between admin and user routes
apps/sim/app/api/v1/admin/workflows/[id]/deploy/route.ts New admin route for deploying/undeploying workflows using extracted helper functions with proper validation and logging
apps/sim/app/api/v1/admin/workflows/[id]/versions/[versionId]/activate/route.ts New admin route for activating specific workflow versions using extracted helper function
apps/sim/app/api/workflows/[id]/deploy/route.ts Refactored undeploy logic to use extracted undeployWorkflow helper function, reducing code duplication
apps/sim/app/api/workflows/[id]/deployments/[version]/activate/route.ts Refactored to use extracted activateWorkflowVersion helper, significantly reducing duplicated database logic

Sequence Diagram

sequenceDiagram
    participant Admin as Admin API
    participant Route as Admin Route Handler
    participant Helper as Persistence Utils
    participant DB as Database
    participant Schedule as Schedule Manager

    Note over Admin,Schedule: Deploy Workflow Flow
    Admin->>Route: POST /api/v1/admin/workflows/:id/deploy
    Route->>DB: Check workflow exists
    DB-->>Route: Workflow record
    Route->>Helper: loadWorkflowFromNormalizedTables(workflowId)
    Helper->>DB: Load blocks, edges, subflows
    DB-->>Helper: Normalized workflow data
    Helper-->>Route: Workflow state
    Route->>Route: validateWorkflowSchedules(blocks)
    Route->>Helper: deployWorkflow({workflowId, deployedBy, workflowName})
    Helper->>DB: Begin transaction
    Helper->>DB: Get max version number
    Helper->>DB: Deactivate all existing versions
    Helper->>DB: Insert new deployment version
    Helper->>DB: Update workflow.isDeployed=true
    Helper->>DB: Commit transaction
    Helper-->>Route: {success, version, deployedAt}
    Route->>Schedule: createSchedulesForDeploy(workflowId, blocks)
    Schedule->>DB: Insert/update schedule records
    Schedule-->>Route: Schedule result
    Route-->>Admin: {isDeployed, version, deployedAt}

    Note over Admin,Schedule: Undeploy Workflow Flow
    Admin->>Route: DELETE /api/v1/admin/workflows/:id/deploy
    Route->>DB: Check workflow exists
    Route->>Helper: undeployWorkflow({workflowId})
    Helper->>DB: Begin transaction
    Helper->>Schedule: deleteSchedulesForWorkflow(workflowId)
    Schedule->>DB: Delete all schedules
    Helper->>DB: Deactivate all versions
    Helper->>DB: Update workflow.isDeployed=false
    Helper->>DB: Commit transaction
    Helper-->>Route: {success}
    Route-->>Admin: {isDeployed: false}

    Note over Admin,Schedule: Activate Version Flow
    Admin->>Route: POST /api/v1/admin/workflows/:id/versions/:vid/activate
    Route->>DB: Check workflow exists
    Route->>Helper: activateWorkflowVersion({workflowId, version})
    Helper->>DB: Get version state
    Helper->>DB: Begin transaction
    Helper->>DB: Deactivate current active version
    Helper->>DB: Activate specified version
    Helper->>DB: Update workflow.deployedAt
    Helper->>DB: Commit transaction
    Helper-->>Route: {success, deployedAt, state}
    Route-->>Admin: {success, version, deployedAt}
Loading

@icecrasher321 icecrasher321 merged commit 4df5d56 into staging Jan 3, 2026
11 checks passed
waleedlatif1 added a commit that referenced this pull request Jan 3, 2026
…ext menu (#2672)

* feat(logs-context-menu): consolidated logs utils and types, added logs record context menu (#2659)

* feat(email): welcome email; improvement(emails): ui/ux (#2658)

* feat(email): welcome email; improvement(emails): ui/ux

* improvement(emails): links, accounts, preview

* refactor(emails): file structure and wrapper components

* added envvar for personal emails sent, added isHosted gate

* fixed failing tests, added env mock

* fix: removed comment

---------

Co-authored-by: waleed <walif6@gmail.com>

* fix(logging): hitl + trigger dev crash protection (#2664)

* hitl gaps

* deal with trigger worker crashes

* cleanup import strcuture

* feat(imap): added support for imap trigger (#2663)

* feat(tools): added support for imap trigger

* feat(imap): added parity, tested

* ack PR comments

* final cleanup

* feat(i18n): update translations (#2665)

Co-authored-by: waleedlatif1 <waleedlatif1@users.noreply.github.com>

* fix(grain): updated grain trigger to auto-establish trigger (#2666)

Co-authored-by: aadamgough <adam@sim.ai>

* feat(admin): routes to manage deployments (#2667)

* feat(admin): routes to manage deployments

* fix naming fo deployed by

* feat(time-picker): added timepicker emcn component, added to playground, added searchable prop for dropdown, added more timezones for schedule, updated license and notice date (#2668)

* feat(time-picker): added timepicker emcn component, added to playground, added searchable prop for dropdown, added more timezones for schedule, updated license and notice date

* removed unused params, cleaned up redundant utils

* improvement(invite): aligned styling (#2669)

* improvement(invite): aligned with rest of app

* fix(invite): error handling

* fix: addressed comments

---------

Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: waleedlatif1 <waleedlatif1@users.noreply.github.com>
Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com>
Co-authored-by: aadamgough <adam@sim.ai>
@waleedlatif1 waleedlatif1 deleted the feat/deployment-admin-routes branch January 4, 2026 20:51
waleedlatif1 pushed a commit that referenced this pull request Jan 8, 2026
* feat(admin): routes to manage deployments

* fix naming fo deployed by
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants