Skip to content

refactor: parameterize deploy/stop pipeline status to eliminate SQL literal duplication#147

Merged
intel352 merged 2 commits intofeat/issue-86-admin-crud-decompfrom
copilot/sub-pr-135
Feb 23, 2026
Merged

refactor: parameterize deploy/stop pipeline status to eliminate SQL literal duplication#147
intel352 merged 2 commits intofeat/issue-86-admin-crud-decompfrom
copilot/sub-pr-135

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

The deploy and stop workflow pipelines were ~95% identical, differing only in the hardcoded status string literal ('active' vs 'stopped') embedded directly in the SQL UPDATE query.

Changes

  • admin/config.yaml — both pipelines (/deploy, /stop):
    • Prepend a set-target-status step (step.set) that declares the semantic difference at the top of each pipeline
    • Change update-status SQL from status = 'hardcoded' to status = ? placeholder
    • Add set-target-status.target_status as the first param in update-status

The update-status step and SQL query are now structurally identical between the two routes. The sole difference is isolated to set-target-status:

# deploy pipeline
- name: set-target-status
  type: step.set
  config:
    values:
      target_status: "active"

# stop pipeline
- name: set-target-status
  type: step.set
  config:
    values:
      target_status: "stopped"
# shared update-status step (identical in both pipelines)
- name: update-status
  type: step.db_exec
  config:
    database: admin-db
    query: "UPDATE workflows SET status = ?, updated_at = ? WHERE id = ?"
    params:
      - "{{index .steps \"set-target-status\" \"target_status\"}}"
      - "{{index .steps \"set-now\" \"now\"}}"
      - "{{index .steps \"parse-request\" \"path_params\" \"id\"}}"

db_exec rejects template expressions in SQL strings (SQL injection guard), so parameterization via ? + params array is the correct approach here.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…tus step

Replace hardcoded status literals in SQL UPDATE queries with a parameterized
approach using step.set to declare target_status at the top of each pipeline.

- Deploy pipeline: set-target-status sets target_status = "active"
- Stop pipeline: set-target-status sets target_status = "stopped"
- update-status query now uses ? placeholder for status value
- status is passed as first param referencing set-target-status.target_status

The only structural difference between the two pipelines is now the value
in set-target-status, making the semantic intent of each pipeline clear
while the update logic (SQL query, param pattern) is identical.

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copilot AI changed the title [WIP] Decompose V1 CRUD routes into pipeline primitives refactor: parameterize deploy/stop pipeline status to eliminate SQL literal duplication Feb 23, 2026
Copilot AI requested a review from intel352 February 23, 2026 14:27
@intel352 intel352 marked this pull request as ready for review February 23, 2026 14:33
@intel352 intel352 merged commit 49d42a8 into feat/issue-86-admin-crud-decomp Feb 23, 2026
@intel352 intel352 deleted the copilot/sub-pr-135 branch February 23, 2026 14:33
intel352 added a commit that referenced this pull request Feb 23, 2026
* feat: decompose V1 CRUD routes into pipeline primitives (#86)

Replace 6 V1 CRUD routes that delegated to V1APIHandler with declarative
pipeline primitives using step.request_parse, step.set, step.db_exec,
step.db_query, step.conditional, and step.json_response:

- POST /api/v1/admin/organizations/{id}/projects (create project)
- POST /api/v1/admin/projects/{id}/workflows (create workflow)
- POST /api/v1/admin/workflows (create workflow standalone)
- PUT /api/v1/admin/workflows/{id} (update workflow with versioning)
- POST /api/v1/admin/workflows/{id}/deploy (activate workflow)
- POST /api/v1/admin/workflows/{id}/stop (stop workflow)

Closes #86

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: parameterize deploy/stop pipeline status to eliminate SQL literal duplication (#147)

* Initial plan

* refactor: encapsulate deploy/stop status difference in set-target-status step

Replace hardcoded status literals in SQL UPDATE queries with a parameterized
approach using step.set to declare target_status at the top of each pipeline.

- Deploy pipeline: set-target-status sets target_status = "active"
- Stop pipeline: set-target-status sets target_status = "stopped"
- update-status query now uses ? placeholder for status value
- status is passed as first param referencing set-target-status.target_status

The only structural difference between the two pipelines is now the value
in set-target-status, making the semantic intent of each pipeline clear
while the update logic (SQL query, param pattern) is identical.

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>

* fix: resolve two syntax errors causing CI failures on PR #135

Bug 1 (admin/admin_test.go:189): TestMergeInto_WithRealAdminConfig had
a broken function ending — the closing brace used 2-space indent and was
followed by ')' instead of a proper '}'. Replace '  }\n)' with tab-indented
'\t}\n}' to correctly close the if-block and the function.

Bug 2 (cmd/server/main.go): The if *databaseDSN != "" block in main() was
missing its closing '}'. The block contained a full inline multi-workflow
implementation that duplicated the existing runMultiWorkflow() function.
Fix by replacing the entire inline block with a delegation call to
runMultiWorkflow(logger), which is the canonical implementation.

Additional fixes applied while resolving Bug 2:
- Remove duplicate "errors" import that caused redeclaration error
- Fix loadConfig() call in runMultiWorkflow to accept all 3 return values
  (was missing the appCfg return value, causing assignment mismatch)
- Wire *multiWorkflowAddr flag into runMultiWorkflow (was incorrectly using
  *addr, leaving multiWorkflowAddr unused and triggering lint failure)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
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