Documentation
¶
Overview ¶
Package provision creates and removes the postgres objects a project owns.
It shells out to psql inside the container rather than linking a driver: docker is a hard requirement anyway, and this keeps the host free of any postgres client and dragonrun's go.mod free of a database dependency.
Index ¶
- func AllDatabases(c *registry.Config) ([]string, error)
- func CreateTenant(c *registry.Config, p registry.Project, db string) error
- func Databases(c *registry.Config, p registry.Project) ([]string, error)
- func DropDatabases(c *registry.Config, p registry.Project) ([]string, error)
- func DropOne(c *registry.Config, db string) error
- func DropRole(c *registry.Config, p registry.Project) error
- func EnsureDB(c *registry.Config, p registry.Project) error
- func EnsureRole(c *registry.Config, p registry.Project) error
- func Harden(c *registry.Config, p registry.Project) error
- func Psql(c *registry.Config, p registry.Project, db string) error
- func Tenants(c *registry.Config, p registry.Project) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllDatabases ¶ added in v0.2.0
AllDatabases lists every non-template database in the cluster, which is the only way to see what is there that the registry does not know about.
func CreateTenant ¶
CreateTenant makes a tenant database owned by the project's role, from template1 so it inherits both the pgbouncer auth hook and the isolation guard -- exactly as one created by the application at runtime would.
func Databases ¶
Databases returns the control database plus every tenant database sharing the project's prefix, which together are everything the project owns.
func DropDatabases ¶
DropDatabases removes every database the project owns. FORCE terminates live backends -- without it a single idle psql session blocks the drop.
func DropOne ¶
DropOne drops a single database. FORCE terminates live backends, including pgbouncer's idle pooled server connections, which otherwise block the drop.
func EnsureDB ¶
EnsureDB creates the control database from template1 -- which is what makes it inherit the pgbouncer auth hook -- then locks it down.
On a shared cluster the default (PUBLIC may CONNECT) would let every project role read every other project's data. Revoking it is the main thing standing between "one convenient cluster" and "one shared blast radius".
func EnsureRole ¶
EnsureRole makes the login role idempotently and syncs its password and CREATEDB bit. CREATEDB is what lets a multi-tenant app create tenant databases at runtime; without Tenants set the role explicitly loses it.
func Harden ¶
Harden re-applies connect privileges to the control database and every tenant database under the project's prefix. Tenant databases are created by the application at runtime, so dragonrun only ever sees them after the fact.
Types ¶
This section is empty.