An extension pack for using medic with Postgres.
This provides a set of checks and shell scripts for managing separate postgres instances per project. It is built to work with medic, though its scripts may be used in isolation.
brew tap synchronal/tap
brew install medic-ext-postgres
Example Brewfile:
tap 'synchronal/tap'
brew 'synchronal/tap/medic'
brew 'synchronal/tap/medic-ext-postgres'
[doctor]
checks = [
# ...
{ check = "postgres", command = "running", args = { remedy = "bin/dev/db-start", user = "${USER}"} },
{ check = "postgres", command = "role-exists", args = { role = "postgres", user = "${USER}" } },
{ check = "postgres", command = "data-directory", args = { data-directory = "./priv/postgres/data", remedy = "bin/dev/db-restart" } },
{ check = "postgres", command = "database-exists", args = { dbname = "my_app_dev", remedy = "mix ecto.reset" } },
# ...
]The checks that work with medic-rs are configured via arguments and/or
environment variables, and can work in concert with tools such as
direnv.
The shell scripts can be configured via the following environment vairables:
PGDATA- the Postgres data directory, as used bypg_ctl. Takes precedence overPG_ROOT. When set withoutPG_ROOT, the log file goes in its parent directory.PG_ROOT- the parent of the data directory ($PG_ROOT/data) and log file ($PG_ROOT/logfile). Defaults to./priv/postgres.PGPORT- the port on which to start Postgres. This defaults to5432.
When used with a combination of mise and direnv, mise wins out in
the shell, and always sets PGDATA when used in combination with its
postgres extension.
To set the data directory when mise is in the shell, the environment
may be set with .config/mise.toml:
[env]
PGDATA = "{{env.PWD}}/priv/postgres/data"Checks for whether a Postgres database is set up for development.
All checks take the following arguments:
dbname- string - name of the database to connect to when accessing Postgres.connect-timeout- integer - seconds to wait before failing to connect.host- string - defaults tolocalhostor to the value ofPGHOST.password- string - defaults topostgresor to the value ofPGPASSWORD.port- integer - defaults to5432or to the value ofPGPORT.sslmode- string - defaults toprefer.user- string - defaults topostgresor the value ofPGUSER.remedy- string - an optional remedy which will override any default remedies.
Where is the data directory for the given Postgres instances?
Required arguments:
data-directory- absolute or relative path to the expected data directory. Defaults toPGDATA.
medic-check-postgres data-directory --data-directory <path>
Does the given database exist?
Required arguments:
dbname
medic-check-postgres database-exists --dbname <name>
Does the give role exists in the database?
Required arguments:
role- the name of the role that should be present.
medic-check-postgres role-exists --role <name>
Is postgres running on the given port? Note that this connects to the database in order to run its check, so must be given valid credentials.
medic-check-postgres running
This package also includes a number of shell scripts.
medic-pg-startmedic-pg-stopmedic-pg-restartmedic-pg-list