Delete Flow and its Data
During development, you may want to completely remove a flow and all its associated data to start fresh. This operation is destructive and should never be used in production.
When to Use This
Section titled “When to Use This”This approach is useful when:
- You need to make breaking changes during development
- You want to clean up test data
- You’re iterating on flow structure and need a fresh start
For production environments, always use versioned flows instead (e.g., my_flow_v1
, my_flow_v2
) to safely deploy new versions while maintaining complete flow history.
Using the Delete Function
Section titled “Using the Delete Function”pgflow includes a delete function that accepts a flow slug parameter:
pgflow.delete_flow_and_data(flow_slug TEXT)
Example:
-- Delete a specific flowSELECT pgflow.delete_flow_and_data('your_flow_slug');
Installing the Function
Section titled “Installing the Function”To install this function, run the following SQL directly in your database using psql or Supabase Studio. This approach helps prevent accidentally deploying this destructive function to production.
The Delete Function
Section titled “The Delete Function”Run this SQL to install the delete function:
/** * Deletes a flow and all its associated data. * WARNING: This is destructive and should only be used during development. * * @param flow_slug - The slug of the flow to delete */create or replace function pgflow.delete_flow_and_data( flow_slug TEXT) returns void language plpgsql as $$BEGIN -- Drop queue and archive table PERFORM pgmq.drop_queue(delete_flow_and_data.flow_slug);
-- Delete all associated data in the correct order DELETE FROM pgflow.step_tasks WHERE step_tasks.flow_slug = delete_flow_and_data.flow_slug; DELETE FROM pgflow.step_states WHERE step_states.flow_slug = delete_flow_and_data.flow_slug; DELETE FROM pgflow.runs WHERE runs.flow_slug = delete_flow_and_data.flow_slug; DELETE FROM pgflow.deps WHERE deps.flow_slug = delete_flow_and_data.flow_slug; DELETE FROM pgflow.steps WHERE steps.flow_slug = delete_flow_and_data.flow_slug; DELETE FROM pgflow.flows WHERE flows.flow_slug = delete_flow_and_data.flow_slug;
RAISE NOTICE 'Flow % and all associated data has been deleted', delete_flow_and_data.flow_slug;END$$;
After Deleting
Section titled “After Deleting”Once you’ve deleted the flow:
- You can compile and deploy a fresh version without conflicts
- The flow slug becomes available for reuse
- All historical data is permanently lost
See Also
Section titled “See Also”- Version your flows - Safe flow updates for production
- Update flow options - Non-breaking configuration changes