Add unprepare-db command to remove monitoring setup
Summary
Implement a CLI command that is the inverse of prepare-db - allowing users to cleanly remove all postgres_ai monitoring infrastructure from a database.
Motivation
Users who have set up monitoring with prepare-db need a way to cleanly remove it when:
- Decommissioning a database from monitoring
- Cleaning up test/dev environments
- Resetting monitoring configuration
Requirements
- Drop helper functions (explain_generic, table_describe)
- Drop postgres_ai.pg_statistic view
- Drop postgres_ai schema
- Revoke permissions (pg_monitor, CONNECT, SELECT on pg_index)
- Optionally drop the monitoring role (with --keep-role to preserve)
- Support Supabase provider (skip role operations)
- Confirmation prompt with --force to skip
- --print-sql for offline SQL plan review
- JSON output mode for automation
Usage
# 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