Skip to content

feat: update migration script to drop old workflow tables with CASCADE - #350

Merged
pikann merged 1 commit into
masterfrom
fix/fix-error-cannot-run-automation-migration
Jul 31, 2026
Merged

feat: update migration script to drop old workflow tables with CASCADE#350
pikann merged 1 commit into
masterfrom
fix/fix-error-cannot-run-automation-migration

Conversation

@pikann

@pikann pikann commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

Migration 000027_add_automation_graph.sql was failing at startup with:

auto-migrate: migrations: exec "000027_add_automation_graph.sql": ERROR: cannot drop table workflow_nodes because other objects depend on it (SQLSTATE 2BP01)

PostgreSQL refuses a plain DROP TABLE when any other object holds a dependency on the target table — in this case workflow_edges has two FK columns (source_node_id, target_node_id) that reference workflow_nodes(id). This can happen when a previous migration run was interrupted mid-transaction, leaving the dependency graph in a partially-applied state.

Solution

Added CASCADE to all five DROP TABLE IF EXISTS statements in the workflow-cleanup section of the migration.

DROP TABLE IF EXISTS workflow_edges CASCADE;
DROP TABLE IF EXISTS workflow_status_transitions CASCADE;
DROP TABLE IF EXISTS workflow_status_rules CASCADE;
DROP TABLE IF EXISTS workflow_nodes CASCADE;
DROP TABLE IF EXISTS workflows CASCADE;

CASCADE instructs Postgres to automatically drop any dependent objects (foreign key constraints, indexes, views) along with the table, making the cleanup idempotent and resilient to whatever state the database is in from a prior partial run.

This is safe because the explicit design decision in migration 000027 is to remove all old workflow data entirely — there is no production data worth preserving from the old workflow feature.

Changes

  • services/api/migrations/000027_add_automation_graph.sql — added CASCADE to the five DROP TABLE IF EXISTS statements that tear down the legacy workflows / workflow_nodes / workflow_edges / workflow_status_rules / workflow_status_transitions tables.

@pullfrog pullfrog Bot left a comment

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.

Reviewed changes

  • Add CASCADE to workflow table drops: The migration now drops the five legacy workflow tables with CASCADE, ensuring any FK constraints or dependent objects from a partially-completed prior migration run don't block the drop.

✅ No new issues found.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@pikann
pikann merged commit 3691439 into master Jul 31, 2026
4 checks passed
@pikann
pikann deleted the fix/fix-error-cannot-run-automation-migration branch July 31, 2026 10:48
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.

1 participant