feat: add unprepare-db command and pg_stat_statements to prepare-db
Closes #95 (closed)
Summary
New: unprepare-db command
- Implements the inverse of
prepare-db, allowing users to cleanly remove all postgres_ai monitoring infrastructure from a database - Drops helper functions (explain_generic, table_describe)
- Drops postgres_ai.pg_statistic view and postgres_ai schema
- Revokes permissions (pg_monitor, CONNECT, SELECT on pg_index)
- Optionally drops the monitoring role (--keep-role to preserve)
New: pg_stat_statements extension
-
prepare-dbnow createspg_stat_statementsextension (with IF NOT EXISTS) -
unprepare-dbdoes NOT drop it (may have been pre-existing)
Improved: Schema safety
- Removed
IF NOT EXISTSfromCREATE SCHEMA postgres_ai - If schema already exists, prepare-db will fail with a clear error
- User should run
unprepare-dbfirst to clean up
Features
- Supports Supabase provider (skips role operations)
- Confirmation prompt with --force to skip
- --print-sql for offline SQL plan review
- JSON output mode for automation
Usage
# Prepare database for monitoring
postgresai prepare-db postgresql://admin@host:5432/dbname --password <mon-pass>
# Remove monitoring setup completely
postgresai unprepare-db postgresql://admin@host:5432/dbname
# Keep the role, only remove objects/permissions
postgresai unprepare-db <conn> --keep-role
# Preview SQL plan
postgresai unprepare-db <conn> --print-sql
Test plan
- Unit tests for buildUninitPlan and applyUninitPlan
- Tests for special character handling in identifiers
- Tests for pg_stat_statements (created, not dropped)
- Tests for schema creation (no IF NOT EXISTS)
- CLI tests for unprepare-db command
- Manual testing against real PostgreSQL database
Edited by Nikolay Samokhvalov