Skip to main content

Module postgres

Module postgres 

Source
Expand description

A throwaway Postgres for the lifetime of one command.

Replaces the sqlx-cli shell-out: the database is created and migrated in-process through sqlx, using the same migrations/ directory the server embeds via server::db::MIGRATOR. One set of migrations, one migrator, no second implementation that can drift.

initdb and pg_ctl remain external programs because they are external programs; there is no library form of them.

Structsยง

Postgres
A running cluster that stops itself when dropped.

Constantsยง

DURABILITY_OFF ๐Ÿ”’
Durability is off on purpose. This cluster is initdbโ€™d moments earlier and dies with the container, so there is nothing for it to protect โ€” every fsync is pure cost, paid on cloud block storage, and 275 of the tests create and migrate a database of their own. Measured worth ~2m30s of a test run.
PORT_RANGE ๐Ÿ”’
Ports tried in order. No allocator to lean on, and pg_ctl -w exits non-zero when the server fails to come up, so a busy port is self-correcting.
TIMEOUTS ๐Ÿ”’
Bounds on how long the server will let a client misbehave.

Staticsยง

MIGRATOR ๐Ÿ”’
The projectโ€™s migrations, embedded at compile time from the same directory server::db::MIGRATOR reads. Embedding needs no database, which is what lets this binary be built before the server it goes on to test.

Functionsยง

create_and_migrate ๐Ÿ”’
run ๐Ÿ”’
start
initdb, start, create the database, migrate it.
start_on_free_port ๐Ÿ”’