MCP server (api.scribase.com) plus the scribase skills for creating a project, adding auth/storage, writing a safe RLS policy, branch-per-PR and the preview-branch-and-confirm workflow. Content ported as-is from the live Scribase agents plugin (rithub.dev/scribase/scribase-agents), packaged with a .grok-plugin/plugin.json manifest for Grok Build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.8 KiB
Markdown
100 lines
3.8 KiB
Markdown
---
|
|
name: scribase-branch-per-pr
|
|
description: Give one pull request its own live Scribase database branch — a copy-on-write fork with its own URL and keys, linked to the PR with a status comment — then merge or clean it up when the PR closes. Use when the user asks for a preview database per PR, branch-per-PR, a staging database for a pull request, "give this PR its own database", or mentions CI needing an isolated backend per branch.
|
|
---
|
|
|
|
# Scribase: one branch per pull request
|
|
|
|
A branch is a copy-on-write fork of production with its own URL and
|
|
publishable key — cheap to create, safe to throw away, and the natural
|
|
isolation unit for a PR's tests and preview deploy.
|
|
|
|
## 1. On PR open: fork and link it
|
|
|
|
```
|
|
branches_create { name: "pr-<number>", data: "sanitized", ttl_hours: 72 }
|
|
```
|
|
|
|
`data: "sanitized"` copies production's shape with anonymized data — the
|
|
right default for a PR a reviewer or CI will actually read; use
|
|
`schema_only` for an empty-but-correct schema, or `snapshot` only if the
|
|
user explicitly wants exact production data on a branch (then treat it as
|
|
sensitive). The call waits and returns the branch's live URL and
|
|
publishable key.
|
|
|
|
Then link it to the PR so GitHub/GitLab shows status and the console shows
|
|
the PR:
|
|
|
|
```
|
|
branch_link_pull_request {
|
|
organization_id, project_id,
|
|
branch_id: "pr-<number>",
|
|
provider: "github", repository: "<owner>/<repo>", number: <pr-number>
|
|
}
|
|
```
|
|
|
|
CLI equivalent (also writes `.scribase/branches/pr-<number>.env` with the
|
|
public URL and key, nothing secret):
|
|
|
|
```bash
|
|
scribase branch create "$ORG" "$PROJECT" "pr-$NUMBER" --data sanitized --ttl 72h
|
|
scribase branch pr "$ORG" "$PROJECT" "pr-$NUMBER" github "$OWNER/$REPO" "$NUMBER"
|
|
scribase branch url "$ORG" "$PROJECT" "pr-$NUMBER"
|
|
```
|
|
|
|
Point CI's test run and any preview deploy at that branch's URL and
|
|
publishable key, never at production.
|
|
|
|
## 2. On every push to the PR: apply pending migrations to its branch only
|
|
|
|
```bash
|
|
scribase migrate "$ORG" "$PROJECT" "pr-$NUMBER" --dir supabase/migrations --apply
|
|
```
|
|
|
|
If the linter blocks a migration (missing RLS, a lock-heavy `ALTER`), that
|
|
is the PR's CI failing for a real reason — do not bypass it; see the
|
|
`scribase-write-rls-policy` skill for the fix.
|
|
|
|
## 3. On PR merge: merge the branch into production, with a human's go-ahead
|
|
|
|
Never merge into production without the explicit approval this step asks
|
|
for; "the PR was approved on GitHub" is not the same approval.
|
|
|
|
```
|
|
branches_merge { branch: "pr-<number>", apply: false } # dry run: show the plan and conflicts first
|
|
```
|
|
|
|
Show the plan and wait. Only after the user approves for this specific
|
|
branch:
|
|
|
|
```
|
|
branches_merge { branch: "pr-<number>", apply: true, confirm: true }
|
|
```
|
|
|
|
CLI: `scribase branch diff "$ORG" "$PROJECT" production "pr-$NUMBER"` then
|
|
`scribase branch merge "$ORG" "$PROJECT" production "pr-$NUMBER"` (add
|
|
`--dry-run` first). For a change that touches RLS or table shape, run the
|
|
full `scribase-safe-change` skill instead of a plain merge — it adds the
|
|
pre-merge backup and the RLS isolation proof this shortcut skips.
|
|
|
|
## 4. On PR close (merged or not): delete the branch
|
|
|
|
A branch nobody deletes is a cost and a stale credential sitting around
|
|
forever. Delete it whether the PR merged or was closed unmerged:
|
|
|
|
```
|
|
branches_delete { branch: "pr-<number>", confirm: true }
|
|
```
|
|
|
|
CLI: `scribase branch delete "$ORG" "$PROJECT" "pr-$NUMBER" --yes`. Branches
|
|
also carry a TTL (`ttl_hours` from step 1) as a backstop, so a PR left open
|
|
for longer than that is not permanently exposing a live branch — but delete
|
|
it on close anyway rather than relying on the TTL.
|
|
|
|
## 5. Report back
|
|
|
|
After step 1, tell the user the branch's URL/key were written to
|
|
`.scribase/branches/pr-<number>.env` and the PR now shows its status
|
|
comment. After step 3, report what was merged and the operation id. Never
|
|
include a secret key value in any report.
|