Files
mesh-catalog/modules/postgres/index.ts
T

26 lines
1.2 KiB
TypeScript

// postgres's events entrypoint, loaded by the per-node tool host (the provisioner container runs
// ./provisioner separately). The database lifecycle events are EMITTED from the provisioner, where
// the lifecycle actually happens (novox/hq ADR 0041/0042):
// module.postgres.database.provisioned — a consumer's database + owning role was created
// module.postgres.database.deprovisioned — that database was removed
// Here in the tool host we react to them, keeping a lightweight audit trail of who was granted a
// database and who lost one — observability the provider itself is best placed to log.
import { on } from "@novox/mesh-sdk/events";
interface DatabaseEvent {
consumer: string;
database: string;
user?: string;
}
await on<DatabaseEvent>("module.postgres.database.provisioned", async (e) => {
console.log(`[postgres] database provisioned for ${e.body.consumer} (db ${e.body.database})`);
});
await on<DatabaseEvent>("module.postgres.database.deprovisioned", async (e) => {
console.log(`[postgres] database deprovisioned for ${e.body.consumer} (db ${e.body.database})`);
});
console.log("[postgres] auditing database lifecycle events");