Skip to main content

cleanup_test_dbs_cmd

Function cleanup_test_dbs_cmd 

Source
pub fn cleanup_test_dbs_cmd(
    dry_run: bool,
    yes: bool,
    maintenance_database: String,
    allow_non_localhost: bool,
    workspace: Option<PathBuf>,
) -> ExitCode
Expand description

djogi db cleanup-test-dbs entry point — drops orphaned djogi_test_<uuid> databases left behind by #[djogi_test] runs killed by SIGKILL / OOM / panic-after-spawn before djogi::testing::teardown_test_db could fire. Triple-gated identical to db reset:

  1. Localhost. DjogiConfig::database.url MUST resolve to 127.0.0.1 / localhost / [::1], unless the operator passed --allow-non-localhost to override (parity with db seed’s lighter gate — sometimes operators run a remote dev cluster).
  2. Non-production. Djogi.toml::profile MUST NOT equal "production". Mirrors db reset’s second gate so the same rules govern any operation that issues DROP DATABASE.
  3. Confirmation. --yes is required, unless --dry-run is passed. --dry-run lists candidates without dropping; no confirmation needed because no side effect occurs. maintenance_database defaults to "postgres" — the conventional administrative DB present on every cluster — and is spliced into database.url’s path component to produce the admin connection URL (the application database itself can’t drop other databases on the same cluster). Exit codes match the db matrix at the top of this module: 0 on success, 1 on runtime / SQL / connect failure, 2 on gate refusal (non-localhost without override, production profile, missing --yes).