<database>-pr-<number>. The action posts one comment with the branch state and a schema diff, updates it on every push, and deletes the branch when the pull request closes or merges.
Workflow
branch, host, port and database-name. Use them in later steps to run migrations against the branch.
Secrets and permissions
LEVELRAIL_TOKEN: use a dedicated token with the flatreadability and two policy statements. Allowdb:writeondatabase:app-db(creates schema branches and lets the CLI check the database) and allowdb:adminondatabase:app-db-pr-*(reads, waits for and deletes only the pull request branches).db:adminon a branch also covers reading it. The token has no admin right on the database itself, so it cannot delete, reset or promote it, and it cannot touch the branches of other databases.- Replace
app-dbwith your database name. The prefix patterndatabase:app-db-pr-*works because policies accept a trailing*. pull-requests: writeis needed only for the comment. Setcomment: "false"to skip it and drop the permission. Setcomment-authorwhengithub-tokenis an App or personal token, so the comment is found by its real author (defaultgithub-actions[bot]).
pull_request event only. Never use pull_request_target: it runs with secrets for code you have not reviewed, and the action refuses to run on it. Pull requests from forks get no secrets from GitHub, so the action skips them with a notice and a green check.
The workflow file is read from the pull request branch. Anyone who can push a branch to the repository can change it and read the token, so treat the token as shared with every committer and keep it minimal. Schema mode is the default for that reason. A full copy needs db:admin on the database itself, which this token does not have, so run full copies with a separate token and only for authors you trust.
Modes and expiry
The branch is not protected by default. Protection blocks delete and expiry, so a protected branch would never be cleaned up by the close step.
pr-close refuses a protected branch unless you pass --force. The ttl is a safety net. A branch that nobody closed expires on its own.
How it works
Onopened, synchronize and reopened the action runs levelrail-cli databases branch pr <database> --pr <number>. The command creates the branch or reuses it if it exists, then waits until it is ready (five minutes by default). The same push twice is safe.
It then runs databases branch diff against the parent and renders the counts and the first 20 changes in a collapsed block. The migration SQL is never put in the comment. The comment carries a hidden marker, so later runs edit it in place.
On closed the action runs databases branch pr-close <database> --pr <number> --yes and edits the comment to “Branch deleted”. A branch that is already gone counts as success.
The comment shows host, port and name only. Credentials are never printed by the action. To connect from your machine:
--reveal is limited to owners, asks for your password and is audited. The same commands work outside GitHub: