Gamend.Release (gamend_core v1.0.1296)

Copy Markdown View Source

Release-time equivalents of the host.* mix tasks.

A release ships compiled .beam files and nothing else — no Mix, no project tree, no mix binary — so mix db.migrate cannot run inside an image built from Dockerfile.release. These functions are what the release's own entrypoint calls instead, usually through bin/gamend db.migrate and its siblings (GamendWeb.CLI):

bin/gamend_host eval "Gamend.Release.createdb()"
bin/gamend_host eval "Gamend.Release.migrate()"

Under Mix the host.* tasks stay the entry point. Both funnel through Gamend.Repo.MigrationPaths, so the two cannot drift on which migrations they consider.

eval starts a fresh node, applies config/runtime.exs and runs the expression without starting the application, which is the point: a migration that fails takes the command down instead of half-booting an endpoint against a database it does not match.

Summary

Functions

Creates the database when it does not exist yet, mirroring mix ecto.create.

Drops the database, mirroring mix ecto.drop. A database that does not exist is not an error.

Runs every pending migration — core's and the host's — on each repo.

What a release runs before it starts serving: create the database when it can, then migrate. Creating may fail (a provisioned Postgres already has the database, and its role may not be allowed to create one), which is reported and passed over; a failed migration raises. bin/gamend start and the Docker image's command both run this.

Rolls every repo back, the way mix db.rollback does: step: n (the last n migrations, 1 when no option is given), to: version or all: true.

Rolls repo back down to version.

The project's seeds script, priv/repo/seeds.exs in the working directory, or nil when there is none. mix host.seed and gamend db.seed both run it.

Functions

createdb()

@spec createdb() :: :ok

Creates the database when it does not exist yet, mirroring mix ecto.create.

Idempotent: an existing database is left alone. Postgres deployments where the server provisions the database already can skip this entirely.

dropdb()

@spec dropdb() :: :ok

Drops the database, mirroring mix ecto.drop. A database that does not exist is not an error.

migrate()

@spec migrate() :: :ok

Runs every pending migration — core's and the host's — on each repo.

prepare()

@spec prepare() :: :ok

What a release runs before it starts serving: create the database when it can, then migrate. Creating may fail (a provisioned Postgres already has the database, and its role may not be allowed to create one), which is reported and passed over; a failed migration raises. bin/gamend start and the Docker image's command both run this.

rollback(opts)

@spec rollback(keyword()) :: :ok

Rolls every repo back, the way mix db.rollback does: step: n (the last n migrations, 1 when no option is given), to: version or all: true.

rollback(repo, version)

@spec rollback(module(), integer()) :: :ok

Rolls repo back down to version.

seeds_file()

@spec seeds_file() :: String.t() | nil

The project's seeds script, priv/repo/seeds.exs in the working directory, or nil when there is none. mix host.seed and gamend db.seed both run it.