Skip to content

Delete Flow and its Data

During development, you may want to completely remove a flow and all its data to make breaking changes, clean up test data, or start fresh after experimenting. This operation is destructive and should only be used in development environments.

The delete function accepts a flow slug parameter and removes all associated data:

pgflow.delete_flow_and_data(flow_slug TEXT)

Example usage in local development:

-- Delete a specific flow and all its data
SELECT pgflow.delete_flow_and_data('analyze_website');

This deletes the flow definition, all runs, queued messages, and task outputs for the specified flow.

Install by running the SQL directly in your database using psql or Supabase Studio.

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