Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,36 @@ The agent-first path — three commands, then hand the work to Claude Code:

```sh
pgrun auth login # opens your browser to authorize; --paste to paste a token instead
pgrun skill install # installs the pgrun-branching skill into ~/.claude/skills
pgrun setup # installs the pgrun-branching skill and PgBot (idempotent; --json for agents)
claude # then: "Add an index to users.email and test it on a pgrun branch"
```

`pgrun setup` is the one install path, whether you run it or the skill asks an agent to:
it installs or refreshes the skill (`--agent claude,codex`, `--project`, `--dir`), makes
[PgBot](https://github.com/pgrundev/pgbot) available (keeps a compatible `pgbot` already on
your PATH, else downloads the pinned release and verifies its checksum), and reports whether
auth is configured. It never edits `AGENTS.md`/`CLAUDE.md` unless you pass
`--agents-md <file>`, and then only between its own markers.

### PgBot: verify database changes

```sh
pgrun bot verify -- bin/rails db:migrate # migration on a disposable PostgreSQL branch, reviewed, cleaned up
pgrun bot verify --compare-pgx --json -- npx prisma migrate deploy # same migration on PGX too, schemas compared
pgrun bot lint <branch> --json # schema findings (read-only)
pgrun bot schema <branch> # schema snapshot (catalog only)
pgrun bot explain <branch> "select * from orders where user_id = $1"
```

`pgrun bot` only inspects PGRun branches (never a connection string you pass it), runs pgbot
read-only, and never sends anything to an AI provider.

`verify` reports one `verdict` — `fail`, `dangerous`, `unsupported` (PGX only), `incomplete`
(the review could not run; never a pass), `error` (infrastructure), `warning` or `pass` — and
`blocking` per an explicit policy (`--block-on`, default `fail,dangerous,incomplete,error`).
Exit 0 = not blocking, 1 = blocking, 3 = only infrastructure errors block. It reviews one
migration against the Safe Copy; it does not detect conflicts between parallel migrations.

The skill teaches Claude when to create a branch, how to inject its
`DATABASE_URL` into only the commands that need it, and when to delete it.
Claude does the branching; you never create a branch by hand.
Expand Down
14 changes: 14 additions & 0 deletions internal/api/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,24 @@ func WaitFailureReason(name, status string) string {
// when returning an error — so callers can still honor --json / isError with
// whatever the API last said.
func (c *Client) WaitForTerminal(ctx context.Context, project string, raw []byte, branch Branch) ([]byte, Branch, error) {
fetched := false
for {
if Terminal(branch.Status) {
// A create response can already say "ready" (an idempotent replay of a request_id,
// or a server that provisions synchronously) but never carries the connection URL:
// only a GET of the single branch does. Fetch it once instead of handing back a
// ready branch with no URL.
if branch.Status == StatusReady && branch.ConnectionURL == "" && !fetched {
fetched = true
var err error
if raw, branch, err = c.GetBranch(ctx, project, branch.Name); err != nil {
return raw, branch, err
}
continue
}
return raw, branch, nil
}
fetched = true
select {
case <-ctx.Done():
return raw, branch, ctx.Err()
Expand Down
27 changes: 27 additions & 0 deletions internal/api/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,30 @@ func TestWaitForTerminal_DeletedStopsImmediately(t *testing.T) {
t.Fatalf("took %s — looks like it ran out the 2s timeout instead of stopping on \"deleted\"", elapsed)
}
}

// A create response that already says "ready" carries no connection URL (only a GET of the single
// branch does): WaitForTerminal fetches it once rather than returning a ready branch without one.
func TestWaitForTerminal_ReadyOnCreateFetchesURLOnce(t *testing.T) {
var gets int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&gets, 1)
w.Write([]byte(`{"id":"b1","name":"x","status":"ready","connection_url":"postgres://u:p@h/x"}`))
}))
defer srv.Close()
c := New(srv.URL, "t")
_, b, err := c.WaitForTerminal(context.Background(), "p", nil, Branch{Name: "x", Status: StatusReady})
if err != nil || b.ConnectionURL != "postgres://u:p@h/x" || atomic.LoadInt32(&gets) != 1 {
t.Fatalf("branch %+v err %v gets %d, want the URL from exactly one GET", b, err, gets)
}
// Ready and not yet credentialed on the GET as well: returned as is, no loop.
srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&gets, 1)
w.Write([]byte(`{"id":"b1","name":"x","status":"ready"}`))
}))
defer srv2.Close()
atomic.StoreInt32(&gets, 0)
_, b, err = New(srv2.URL, "t").WaitForTerminal(context.Background(), "p", nil, Branch{Name: "x", Status: StatusReady})
if err != nil || b.ConnectionURL != "" || atomic.LoadInt32(&gets) != 1 {
t.Fatalf("branch %+v err %v gets %d", b, err, gets)
}
}
Loading
Loading