# Command reference

Source: https://bogie-go.com/docs/commands.html

Tasks use a colon (`db:migrate`); the rest are plain words. `bogie help` prints the authoritative short version of this page from inside an app.

## Bogie, outside an app

| Command | Does |
| --- | --- |
| `bogie new NAME [--module=PATH] [--id=bigint\|uuid] [--jobs]` | Generates a new service in `./NAME`. `--id` picks the primary key scheme for the whole app: `bigint`, the default, or `uuid`. See [Id schemes](https://bogie-go.com/docs/models.html#ids). |
| `bogie version` | Prints the version. |
| `bogie help` | This text. |

## Bogie, inside an app

Found by its `bogie.toml`, from any subdirectory.

| Command | Does |
| --- | --- |
| `bogie generate GENERATOR NAME`, `bogie g` | Runs a generator: `scaffold`, `scaffold_controller`, `model`, `migration`, `controller`, `service`, `job`, `seed`, `config`, `authentication`, `policy`. `bogie g -h` for its own usage, inside an app. |
| `bogie destroy GENERATOR NAME`, `bogie d` | Removes what a generator made, registration included. |
| `bogie doctor` | Checks markers, pinned tools and layout files; confirms every controller is constructed and mounted. Since v0.7.0, `-h` / `--help` / `help` prints usage and exits 0, both inside an app and outside one (it used to fail with "not inside a bogie app" outside, and ignore the flag inside). It does not check Docker or Postgres. |
| `bogie model:sync [TABLE]` | Brings a model in line with the schema after a migration, generated or hand-written: adds the field for each new column, removes the field for each column a migration dropped, and merges the regenerated queries, store and factory into your copies. `Validate`, the views, the controllers and the specs stay yours. Without `TABLE` it syncs every model. Refuses on a dirty git tree. See [Models and migrations](https://bogie-go.com/docs/models.html#model-sync). |
| `bogie app:update [--pretend]` | Moves the app to the installed Bogie's layout: a three-way merge between what the recorded version generated, what this version generates, and the file on disk. Refuses on a dirty git tree; a real overlap leaves conflict markers. |
| `bogie server`, `bogie s` | Runs the app; migrates at boot. In development it runs under Air: save a file and it rebuilds and restarts. |
| `bogie worker` | Works the job queue (apps with jobs; `g job` adds them to one that has none). Reloads under Air in development, same as `bogie server`, to its own binary so the two can run side by side. |
| `bogie routes` | Every mounted route, method, path and handler. It boots the app the way `serve` does, so the list is what is actually wired. Prints in development only; in `test` or `production` it exits 0 with no output. |
| `bogie test [PKGS]`, `bogie t` | `go test -p 1 -race -cover ./...`: Ginkgo specs, one package at a time. |
| `bogie lint` | gofmt check, `go vet`, golangci-lint. |
| `bogie ci` | Every check, locally, then sign off: `bin/ci`. |
| `bogie db:create` | Creates the database for the current environment. |
| `bogie db:drop` | Drops it, with `--yes` added for you. |
| `bogie db:prepare` (`db:setup`) | Create, migrate, seed. |
| `bogie db:reset` | Drop then prepare. |
| `bogie db:migrate` | Applies pending migrations. |
| `bogie db:migrate:status` | Which migrations have run, which are pending. |
| `bogie db:migrate:redo` | Rolls the last migration back and re-applies it. |
| `bogie db:rollback` | Rolls back the most recent migration. |
| `bogie db:version` | The current schema version. |
| `bogie db:status` (`bogie db status`) | Since v0.7.0. A read-only look, in the tool itself, at the database the server would connect to: host, port, database, Postgres version, the latest applied goose migration and how many files are still pending, and how many tables. It resolves the URL the way `config.Load` does, so it cannot point somewhere `bogie server` would not. The CLI now depends on `github.com/jackc/pgx/v5`; a generated app gains no command and no import. On a connection failure it keeps the driver's error, adds a one-line hint, and exits non-zero. See [Models and migrations](https://bogie-go.com/docs/models.html#db-status). |
| `bogie db:seed` | Runs every seed in `db/seeds`, every time, in registration order; each must be safe to run twice. |
| `bogie credentials:edit [-e ENV]` | Opens the encrypted settings for editing. |
| `bogie credentials:show [-e ENV]` | Prints the decrypted file. |
| `bogie credentials:get [-e ENV] KEY` | Prints one value. |

Tasks that destroy pass `--yes` on your behalf here, the way a laptop command should; the app's own binary in a deployed container keeps asking. `bogie db:migrate:up` or any other near-miss points at the nearest real task rather than printing the whole usage.

The reload under `bogie server` and `bogie worker` is development only: set `<NAME>_ENV` to anything else and the plain compiled binary runs with no watcher. Air is pinned as a `go tool` dependency in the app's own `go.mod`, next to goose, sqlc and credentials, so a fresh clone needs only Go. Its settings are `.air.toml`; deleting that file turns reload off.

## Generators: bogie g / bogie d

| Generator | Arguments | Writes |
| --- | --- | --- |
| `migration` | `NAME [field:type ...]` | `db/migrate/<stamp>_NAME.sql`. `create_<table>`, `add_<x>_to_<table>` and `remove_<x>_from_<table>` write their SQL. |
| `model` | `NAME [field:type ...]` | The migration, `db/queries/<table>.sql`, `app/models/<name>.go` and the store's `db/adapter/<table>.go`, their two specs and a factory; then runs sqlc into `db/sqlc`. |
| `scaffold` | `NAME [field:type ...] [--policy]` | The model, plus `app/views/<table>.go` and a `<Table>Controller` with real handlers over the store, registered. The model is singular, the rest plural. `--only index,show` writes just those actions, with their routes, views and specs (the model half is always whole). `admin/NAME` is a model of its own, `admin_page` with table `admin_pages`, whose `PagesController` answers at `/admin/pages`. `--policy` (v0.7.0) checks a policy in a service and answers 403 when it denies; it needs `g authentication token` first, and adds `user_id` when the model does not have one. See [Authorization](https://bogie-go.com/docs/authorization.html). |
| `scaffold_controller` | `[NS/]RESOURCE` | The HTTP half of a scaffold, for a model that already exists: `admin/categories` mounts the five actions over the `category` store under `/admin/categories`, reading the attributes from `app/models`. A namespaced one writes views of its own, `app/views/admin_categories.go`. `--only` works here too, and `--policy` when the model already has `user_id`. |
| `controller` | `NAME [action ...]` | `app/controllers/<name>_controller.go`, one controller in one file, registered: a field, a wire line and a mount above each marker. Name a resource in the plural. `admin/NAME` puts it in the admin namespace, `app/controllers/admin_controllers/`, made on first use and registered the same way. |
| `service` | `NAME` | `app/services/<name>/`, `ctx` first, no HTTP, not wired anywhere. |
| `job` | `NAME [--every CRON]` | `app/jobs/<name>.go`, a River job, registered above `bogie:jobs`; the first one on an app with no jobs adds them first, merged in like `app:update`. Since v0.7.0, `--every "0 9 * * *"` also registers a River periodic job on that cron schedule (`RunOnStart` off). A restart can skip a scheduled run. See [Background jobs](https://bogie-go.com/docs/jobs.html#periodic). |
| `seed` | `NAME` | `db/seeds/<name>.go`, registered above `bogie:seeds` in `db/seeds/seeds.go`. Unlike a migration, `db seed` runs every seed every time: write it safe to run twice. |
| `config` | `[GROUP] key[:type][:flag][=value] ...` | A typed group of the credentials file in `config/<group>.go`, registered, with development values; or keys into an existing group (`server`, `database`); or, with no group, flat top-level keys. See [Configuration](https://bogie-go.com/docs/configuration.html). |
| `authentication` | `SHAPE` | A middleware on a route group, its config key with a development value written to the credentials, and a `WithX` group helper on the root `Server`. `SHAPE` is `secret` (a trusted service calls this one), `token` (bearer JWT a user presents) or `api_key` (keys for machine clients, with a table and `api_keys:create`). Since v0.7.0 the token shape keeps an optional `role` claim and `MintFor(subject, role, ttl)`. |
| `policy` | `NAME` | Since v0.7.0. `app/policies/<name>_policy.go`: `CanIndex`, `CanShow`, `CanCreate`, `CanUpdate`, `CanDestroy` on `policies.Name`, a table spec, and a service that checks the policy. The model already exists and has `user_id`. Defaults deny except what the actor owns. See [Authorization](https://bogie-go.com/docs/authorization.html). |

Flags: `--pretend` reports without writing (even `g job` on an app with no jobs, which only says `--jobs would be added first`, and `g job --every` too), `--force` overwrites a file that differs, `--only ACTIONS` limits a scaffold to the actions listed, `--policy` on `scaffold` and `scaffold_controller`, `--every CRON` on `job`, `--skip-sqlc` skips the sqlc run. Run a generator again and each file is reported `identical`, or `conflict` if it differs from what the generator would write; only `--force` overwrites. Attributes are `field:type`, with `:index` or `:uniq` after the type: `string text integer bigint boolean datetime uuid jsonb references`. A field with no `:type` defaults to `string`. A `references` field names the other model: `post:references` is `post_id`. `:null` follows a type for a column that may be NULL (`archived_at:datetime:null`).

`bogie d GENERATOR NAME` removes what the generator of the same name created: its files, and for a controller the three lines that registered it. `bogie d scaffold_controller admin/categories` removes just the controller half. A namespaced controller's package goes too once it holds no controller; `bogie d authentication token` also removes its config group, leaving the development value harmless in the credentials file. `bogie d policy post` removes the policy, its spec and its service, and refuses when a controller is still wired to that service; `bogie d scaffold post` removes the resource and the policy together. `bogie d job` removes the periodic schedule line when it is there, with the worker.

`api_key` registers a subcommand on the app's own binary, not on `bogie`: `bogie api_keys:create NAME` reaches it through the same proxy rule as `db:*`, any colon task `bogie` does not know itself is shorthand for the binary's own, so it runs `blog api_keys create NAME`.

## The app binary itself

A plain Go CLI with spaces, the form `bogie` accepts too (`bogie db prepare` works from outside, since the colon tasks above are shorthand for exactly these):

| Command | Does |
| --- | --- |
| `blog serve` | Runs the HTTP server. |
| `blog worker` | Works the job queue (apps with jobs enabled). |
| `blog db create` | Creates the database this environment points at. |
| `blog db drop --yes` | Drops it; refused in production. |
| `blog db prepare` | Create if needed, migrate, seed. |
| `blog db seed` | Runs every seed in `db/seeds`; each one runs again every time. |
| `blog routes` | Every mounted route (development only). |
| `blog migrate status` | Which migrations have run, which are pending. |
| `blog migrate version` | The current schema version. |
| `blog migrate up` | Applies every pending migration (also done at boot). |
| `blog migrate down --yes` | Rolls back the most recent migration. |
| `blog migrate down-to N --yes` | Rolls back until the schema is at version N (0 = empty). |

These run against whatever database the current `<NAME>_ENV` selects, including on a deployed host: `docker exec <container> blog migrate status`.

## make targets

| Target | Does |
| --- | --- |
| `make help` | Every task. |
| `make up` | Start Postgres (Compose) and wait until it is healthy. |
| `make down` | Stop it, keeping the data. |
| `make reset` | Stop it and destroy the data. |
| `make logs` | Tail the containers. |
| `make psql` | Open a shell on the development database. |
| `make credentials` | Edit the encrypted settings (development); `ENV=production` for its own file and key. |
| `make build` | Compile the binary. |
| `make server` | Run the HTTP server. One boot, no reload; drop to this for a single set of logs. |
| `make worker` | Work the job queue (apps with jobs enabled). One boot, no reload. |
| `make test` | Run the suite with coverage, in the test environment (needs `make up`). |
| `make sqlc` | Regenerate `db/sqlc` from `db/queries` against `db/migrate`. |
| `make vet` | Stdlib static analysis. |
| `make fmt` | Format. |
| `make lint` | gofmt check + golangci-lint. |
| `make ci` | Every check, locally; green ends with `gh signoff` (`bin/ci`). |
| `make tidy` | Prune and verify the module graph. |
| `make db-create` | Create the database; an existing one is fine. |
| `make db-drop` | Drop the database and every table in it. |
| `make db-prepare` | Create if needed, migrate, seed. |
| `make db-reset` | Drop it and rebuild it from the migrations. |
| `make db-migrate` | Apply pending migrations (deployed containers do this at boot). |
| `make db-migrate-down` | Roll back the last migration; drops its tables. |
| `make db-rollback` | Alias for `db-migrate-down`; the same task. |
| `make db-migrate-to V=<version>` | Roll back to a version. |
| `make db-rollback-to` | Alias for `db-migrate-to`; the same task. |
| `make db-migrate-status` | Which migrations have run, and which are pending. |
| `make db-version` | The current schema version. |
| `make db-migrate-redo` | Roll the last migration back and re-apply it. |
| `make db-seed` | Apply every seed in `db/seeds`, through the binary (safe to run again). |
| `make g_migration_<name>` | Author a migration (`go tool goose`). |
