Skip to content

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.

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.

pgflow includes a delete function that accepts a flow slug parameter:

pgflow.delete_flow_and_data(flow_slug TEXT)

Example:

-- Delete a specific flow
SELECT pgflow.delete_flow_and_data('your_flow_slug');

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.

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
$$;

Once you’ve deleted the flow:

  1. You can compile and deploy a fresh version without conflicts
  2. The flow slug becomes available for reuse
  3. All historical data is permanently lost