Skip to content
Skillpedia
APIs & servers (backend)31k Β· #9264

postgres-adopt

What it does

This skill checks whether your GBrain uses its built-in local database or Postgres. It helps you move an existing local brain to Postgres while keeping its history.

When to use it

  • βœ“When you want to know which database engine your brain is using.
  • βœ“When you want to move a local brain to Postgres and keep its history.
  • βœ“When you need a Postgres database for a brain that many computers or people will use.

Skill link

https://github.com/garrytan/gbrain/blob/master/plugin-variants/gbrain-coding/skills/postgres-adopt/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/garrytan/gbrain/blob/master/plugin-variants/gbrain-coding/skills/postgres-adopt/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œCheck which database my brain uses, and if it is the basic one, plan a move to Postgres.”

5 new skills a week. 1 minute to read.

How it works

The agent first reads the current setup without changing anything. It then shows a migration plan and waits for your approval before copying data and checking every table.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Postgres Adopt

The engine is the brain's foundation: PGLite is the zero-config floor, Postgres is where concurrency, multi-machine access, and 1000+ pages live. This skill answers "which one am I on?", prefers Postgres when the operator wants it, and moves data safely β€” never by flipping config.

Contract

This skill guarantees:

  • Detection is engine-free and read-only: gbrain engine status --json answers with the database down (that is the point of the command).
  • Engine changes NEVER happen by editing config. A PGLite brain moves with gbrain migrate --to postgres (alias --to supabase), which graduates it: plan first (exit 3), run only with the user's --yes --expect <plan_hash>, verify every table, then flip routing. This skill wraps it; it never reimplements it.
  • The target URL never appears in a command, transcript or output: it lives in GBRAIN_TARGET_URL and every command uses --url-env GBRAIN_TARGET_URL.
  • Provisioning consent is explicit: the docker rung needs --allow-docker, creating a database on a local server needs --allow-create-db. Headless mutation of infrastructure the operator didn't opt into never happens.

Step 1 β€” Detect

gbrain engine status --json

Branch on the output:

  • effective_engine: "postgres" and (optionally) --probe says ok β†’ report healthy, done.
  • effective_engine: "postgres" but the probe fails β†’ this is an ACCESS problem, not an adoption problem: route to db-repair.
  • config_file_engine differs from effective_engine β†’ an env URL is overriding the config file; tell the operator which one wins β€” the signal is db_url_source (env:GBRAIN_DATABASE_URL / env:DATABASE_URL means env wins; env.note additionally fires when both env URLs are set or the cwd-.env shadow guard excluded one).
  • thin_client: true β†’ the brain lives on a remote server; engine choices belong to that host. Stop.
  • effective_engine: null (no brain) β†’ Step 2.
  • effective_engine: "pglite" with data β†’ Step 3.
  • The output has a graduation block whose state is not none (in progress, interrupted, graduated or split) β†’ Step 4.

Step 2 β€” Fresh install, Postgres-first

gbrain init --prefer-postgres

The ladder tries, in order: an env URL β†’ Supabase Management-API discovery (SUPABASE_ACCESS_TOKEN, plus SUPABASE_PROJECT_REF on multi-project accounts and SUPABASE_DB_PASSWORD for the connection string) β†’ a local Postgres (only when PGHOST/PGPORT/PGUSER/PGPASSWORD are set or --local-postgres is passed) β†’ docker β†’ PGLite. Each unusable rung prints a one-line note and falls through; nothing is silent.

  • Ask the operator BEFORE adding --allow-docker (it creates and owns a gbrain-postgres container that survives reboots) or --allow-create-db (it runs CREATE DATABASE on their local server).
  • --json reports {engine, ladder_rung, url_source} β€” relay which rung won.
  • If the ladder lands on PGLite, that is a fine outcome: say so, and note the upgrade path below is available whenever they want it.

Step 3 β€” Existing PGLite brain: plan, ask, run

Full reference: Move a PGLite brain to Postgres.

  1. Target URL. Ask the user to put the connection string in an environment variable without pasting it into the conversation (read -rs GBRAIN_TARGET_URL && export GBRAIN_TARGET_URL). On Supabase use the transaction pooler; on an IPv4-only host also set GBRAIN_DIRECT_DATABASE_URL to the session pooler.
  2. Plan. This changes nothing and exits 3 with the confirmation_required document:
    gbrain migrate --to postgres --url-env GBRAIN_TARGET_URL --json
    
    Relay user_message, what moves, what stays on this computer, blockers and the estimate. Stop and wait for the user. A blocker with its own fix gets cleared first (ask when it says ask_user).
  3. Run, after the user agrees. Use fix.command from the document:
    gbrain migrate --to postgres --url-env GBRAIN_TARGET_URL --yes --expect <plan_hash>
    
    preview_changed means the plan changed: go back to step 2. For thousands of pages run it in the background and poll gbrain migrate --status --json.
  4. Report. Relay the target doctor verdict from the run's output, that existing tokens, OAuth clients and local writers stay valid, the gbrain mcp expose foll
FAQ

Will my database address appear in the output?

No. The address is kept in an environment variable and is never printed in commands or results.

Does it create databases without asking?

No. Creating a database or starting a Docker container needs explicit flags from you.

Can I switch engines by editing a config file?

No. Engine changes are not made by editing config. The move is done with the migration command.

Details

Original description by the author

Detect which gbrain engine is in use (PGLite vs Postgres), prefer Postgres for agent-harness installs, install/provision Postgres (Supabase discovery via SUPABASE_ACCESS_TOKEN, local Postgres, opt-in Docker), and move an existing PGLite brain to Postgres with its history (plan, ask, run). Detection is one engine-free command; the install ladder is one flag.

repo: garrytan/gbrain

Popularity

GitHub stars
31k
Ranking position
#9264
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills