Skip to content

cleanup_schema() doesn't drop functions, leaving public schema dirty #4

@affandar

Description

@affandar

Problem

When using the public schema (the default), provider.cleanup_schema() leaves stored procedures behind. This is because:

  1. cleanup_schema() calls the SQL cleanup_schema() function which only drops tables, not functions
  2. The Rust code only runs DROP SCHEMA CASCADE for non-public schemas (as a safety measure)
  3. Result: stored procedures accumulate in the public schema across test runs

Impact

  • Tests using public schema may see interference from orphaned functions
  • The public schema becomes "dirty" over time
  • Function signature changes in migrations may fail because old function signatures still exist

Root Cause

The SQL cleanup_schema() function only drops tables:

CREATE OR REPLACE FUNCTION cleanup_schema()
RETURNS VOID AS $cleanup$
BEGIN
    DROP TABLE IF EXISTS instances CASCADE;
    DROP TABLE IF EXISTS executions CASCADE;
    -- ... only tables, no functions
END;
$cleanup$ LANGUAGE plpgsql;

Solution

Add DROP FUNCTION IF EXISTS for all stored procedures inside cleanup_schema().

Reference

Note: duroxide-pg-opt already has the correct pattern with function drops in its cleanup_schema().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions