SupaForge

io.github.akalsoftware由 GitHub 帳號 akalsoftware 發布v0.0.41更新於 Nov 7, 2026

Find and fix drift between Supabase environments: schema, RLS, roles, auth, storage and more.

概覽

AI 產生的概覽

SupaForge 比較兩個 Supabase 環境,回報 schema、RLS、驗證、儲存等方面的差異,並可將目標環境同步成與來源一致。

可以做什麼
  • 列出設定中的環境,以及預設的來源與目標,不傳回憑證
  • 比較兩個環境並回報所有差異,附上 SQL、漂移分數和 sync 將執行的計畫
  • 在目標上執行該計畫,可先在一次性副本上預演
  • 取得最近一次 diff 或 sync 中某項檢查的結果
  • 把差異寫成遷移檔,包含授權語句與可還原的 DOWN
  • 將某個環境的時間點快照存成本地檔案
適用情境
適合專案有多個 Supabase 環境(例如開發與正式)且已出現漂移時,讓助理先呈現差異與確切的修復計畫,再決定是否執行。也適合從漂移產生遷移檔或建立快照。
執行需求
透過 npx 以 stdio 在本機執行,需要 Node.js 20 或更新版本,並在專案目錄提供 supaforge.config.json(以 --project 指定)。設定中包含 PostgreSQL 連線字串,可選 projectRef 與 accessToken 以啟用 Management API 檢查,值可從環境變數讀取。需要能連線資料庫與 Supabase API 的網路。
安裝前請注意
sync 工具會寫入目標資料庫;伺服器要求先執行 diff 並向使用者展示計畫後再同步。刪除資料表、欄位等破壞性修復除非設定 allowDestructive,否則會被攔下。create_migration 與 take_snapshot 會在本機寫入檔案。設定涉及連線字串與存取權杖,伺服器聲稱不會傳回這些憑證。快照不是備份:除設定的資料表外不含任何資料列,也不含儲存檔案。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 SupaForge,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

supaforge

Diff and sync your Supabase environments.

SupaForge compares two Supabase projects (dev and prod, say) across everything that makes up a project, not just the schema. It reports every difference and makes the target match the source. Fixes run in dependency order, in one transaction, and can be proved on a throwaway copy before anything changes. With a single project, it snapshots, restores and clones it.

  • The whole project. It covers schema, RLS, storage, auth, Edge Functions, cron, webhooks, Realtime, queues, partition sets, Vault, extensions, grants, reference data and migration history.
  • Safe by default. Every write needs --apply, and anything that loses data or opens up access also needs --allow-destructive. A failed apply leaves the target exactly as it was.
  • Production-aware. Each fix says what it does to a live database: the lock it holds and on which table, whether it may rewrite the table or scan every row, whether it can't run in a transaction.
  • Provable. --prove rehearses the migration and refuses to apply one that wouldn't reproduce the source or would lose rows.
  • Anywhere. It works with Supabase Cloud, self-hosted stacks, plain PostgreSQL targets, CI pipelines and AI agents (MCP).

Built by Akal.

Quick start

bash
npm install -g @akal/supaforge
supaforge init              # create supaforge.config.jsonsupaforge diff              # what has drifted?supaforge diff --detail     # with the SQLsupaforge diff --apply      # fix the target

Everything that writes previews first. Add --apply to make it happen.

Install

npmnpm install -g @akal/supaforge, or run it with npx @akal/supaforge
Homebrewbrew install akalsoftware/tap/supaforge
Dockerdocker run --rm -v "$PWD:/work" ghcr.io/akalsoftware/supaforge diff
GitHub Actionsakalsoftware/supaforge-action — see CI
VS Code and its forksThe SupaForge extension: commands, and the MCP server for the editor's agent. Each release carries it as a .vsix
Cursor, VS Code, ClaudeOne-click installs of the MCP server — see MCP

It needs Node.js 20 or newer. DBDiff, its diff engine, comes with it as a native binary for your platform, so there is nothing else to install. The Docker image needs nothing at all, and carries the PostgreSQL client tools --prove uses; pass connection strings with -e, and mount the project at /work.

What it compares

CheckWhat it readsFixed with
Schema@dbdiff/cli: every schema you ownSQL
Reference dataRows of the tables in checks.data.tablesSQL
RLS policiespg_policies, compared by meaning, not textSQL
RLS coverageTables in the target with RLS off (target only)SQL, opt-in
Edge FunctionsManagement API, Studio, or a functions directoryDeploy command
StorageBuckets and their policies (objects are never copied)API and SQL
Auth configManagement API, or GoTrue on self-hostedAPI (hosted)
Cron jobscron.jobSQL
QueuesSupabase Queues (pgmq.meta), created and dropped through pgmqSQL
Partition setspg_partman registrations (part_config), made with create_parentSQL
WebhooksTriggers calling supabase_functions.http_requestSQL
RealtimePublications, and policies on realtime.messagesSQL
VaultSecret names and descriptions (values can't be read)Command to run
Extensionspg_extensionSQL
Migration historyLocal migration files against supabase_migrations (target only)SQL, opt-in
Roles and grantsCustom roles, and grants on tables, views, sequences and functions, including anon, authenticated, service_roleSQL

The schema check covers tables, columns, keys, indexes, partitions, views, materialized views, functions, aggregates, triggers, event triggers, rules, sequences, enums, composite and range types, domains, casts, extended statistics, text search configurations and dictionaries, foreign servers, user mappings and foreign tables, policies, default privileges, replica identity, statistics targets, extensions and comments. A renamed column, table or sequence is renamed, keeping its rows, rather than dropped and created again. It runs in every schema except Supabase's own (auth, storage, and so on) and those in ignoreSchemas. Objects owned by an extension belong to it and aren't compared. Objects of a kind it doesn't compare, such as operator classes, are named under the check so you can look at them by hand; they aren't counted as drift.

A check that can't run, for example without API credentials, says so and why. It's never reported as a clean pass.

Commands

supaforge init                    Create a config interactivelysupaforge diff                    Report drift (alias: hukam)supaforge sync                    Alias for diff --apply
supaforge snapshot --apply        Capture an environment's structure and configurationsupaforge restore --apply         Rebuild a database from a snapshot or migrationssupaforge clone --apply           Copy a remote database to a local one
supaforge migrate create          Write a migration file from the current driftsupaforge migrate list            Local migrations, applied and pendingsupaforge migrate run --apply     Run pending migrationssupaforge migrate baseline --apply  Mark migrations applied without running them
supaforge report                  Recent runs, from a local logsupaforge mcp                     MCP server for AI agentssupaforge help <command>          Every flag, e.g. help diff

Useful diff flags:

FlagDoes
--check=rls / --skip=storageOne check, or all but some (--skip repeats)
--tables=orders,items / --exclude-tables='*_log'Scope the schema and data checks
--only=<id,...>Apply only these findings (ids come from --json, globs allowed)
--dry-runPrint the fixes in the order they'd run, run nothing
--proveRehearse the fixes on a throwaway copy first
--source-dir <dir>Compare a directory of schema files (such as supabase/schemas) with the target instead of a source database
--allow-destructiveAlso apply drops and deletes
--apply-postureAlso apply the target-only checks' fixes
--no-transactionApply fix by fix, keeping what works
--no-snapshotRead each query on its own. By default each database is read as of one instant, so a change made while the scan runs is seen by all of it or none; as with pg_dump, what it reads stays locked until the scan ends
--json / --ciMachine-readable output; CI annotations and exit codes

Applying fixes safely

  • Preview first. diff, snapshot, restore, clone and migrate run write nothing without --apply.
  • Destructive fixes need a second flag. Dropping a schema, table or column, deleting or truncating rows, and removing an RLS policy are reported but skipped until you add --allow-destructive. migrate run uses the same gate.
  • Dependency order. Fixes run in dependency order: functions before the triggers that call them, columns before their indexes, drops last. A changed object that has to be dropped and recreated is a single fix.
  • One transaction. If a fix fails, the whole set rolls back and the target is unchanged. A fix the target can't hold, because it needs an extension or a Supabase schema the target lacks, is skipped with the reason, and the rest still applies.
  • --prove. The fixes are replayed on a copy of the target's structure, made on the target's own server, the way the apply will run them, with a sample of each table's rows. Nothing is applied unless the result matches the source and the rows survive, and nothing is applied if the proof can't run. It also names the tables the fixes rewrite. Changes a copy can't hold, such as cron jobs (pg_cron lives in one database per server), are listed as not proved.
bash
supaforge diff --dry-run                 # the plan, in ordersupaforge diff --apply --prove           # rehearse, then applysupaforge diff --apply --only='schema-create-*'

Posture checks

RLS coverage and migration history look at the target alone, so they report the same findings whichever pair you diff. They're scored separately (Posture score), don't set the exit code unless you pass --fail-on-posture, and their fixes apply only with --apply-posture, or when you name the check, as in --check=rls-coverage --apply. Applying them blindly would move the target away from the source.

Snapshot, restore and clone

bash
supaforge snapshot --env=prod --apply                     # capturesupaforge snapshot --env=prod --migration --apply         # and write what changed since the last onesupaforge restore --env=local --from-snapshot=latest --applysupaforge clone --env=prod --apply                        # local copy, data included

A snapshot records a project's structure and configuration: schema, RLS policies, cron, webhooks, extensions, storage, auth, Edge Functions, reference data, Realtime, Vault names and grants. It is not a backup. It holds no rows beyond checks.data.tables, and no stored files. Its schema is written as SQL by pg_dump, which has to be at least as new as the server; without one the snapshot can still be diffed but not restored, and snapshot exits 1 unless --allow-schema-json-only says that is enough.

restore --from-snapshot puts back:

RestoredNotes
Extensions, schema, RLS policies, cron jobs, webhooks, Realtime publications, grantsAs SQL, in dependency order. Roles a policy or grant names are created first
Storage policies and bucketsBucket rows are created when the target has a storage schema; files never are
Reference dataThe rows of checks.data.tables, parents before children, sequences moved past the restored ids

It can't put back auth config, Edge Functions (deploy them with supabase functions deploy), or Vault secret values. Each of these is named in the output.

  • Targets. Restore runs as one transaction and expects an empty database. --force clears the snapshot's own schemas first (never Supabase's) and puts back the triggers and policies outside them that depended on what it cleared. A restore or apply that looks likely to need more locks than the target allows in one transaction says so before it starts; --no-transaction commits as it goes instead.
  • Plain PostgreSQL. Restoring into plain PostgreSQL works. What can't exist there is skipped and named: a foreign key to auth.users, a webhook, an extension the server doesn't ship, and everything that needs it.
  • Exit code. A restore that left anything out exits 1. So does one that refused to run.
  • JSON. --json prints only JSON, for a preview too.

clone copies a remote database into a local server with pg_dump and pg_restore (--schema-only to leave the rows behind). Extensions the local server has are installed first. Objects it couldn't restore are listed by cause. Afterwards the config's target points at the clone, so a bare diff --apply writes there rather than to the remote.

Migrations

bash
supaforge migrate create --name=add_orders   # from the drift between source and targetsupaforge migrate run --env=prod             # previewsupaforge migrate run --env=prod --apply
  • Files and history. Files live in supabase/migrations (set checks.migrations.dir to change it). Applied versions are recorded in supabase_migrations.schema_migrations, the Supabase CLI's table.
  • Destructive statements. migrate create lists any it wrote, and migrate run needs --allow-destructive to run them.
  • History table permissions. On a self-hosted stack the history table can belong to an admin role. SupaForge then says which GRANT is needed instead of failing with a bare permission error.
  • Projects without a tracked history. checks.migrations.mode decides how the migration-history check reports them: auto (one note when nothing is tracked), warn or ignore.

Configuration

json
{  "environments": {    "dev":  { "dbUrl": "$DEV_DATABASE_URL",  "projectRef": "abc123", "accessToken": "$SUPABASE_ACCESS_TOKEN" },    "prod": { "dbUrl": "$PROD_DATABASE_URL", "projectRef": "xyz789", "accessToken": "$SUPABASE_ACCESS_TOKEN" }  },  "source": "dev",  "target": "prod",  "checks": {    "data": { "tables": ["plans", "feature_flags"] },    "exclude": ["edge-functions"]  }}
FieldMeaning
dbUrlPostgreSQL connection string. $VAR and ${VAR} are read from the environment
projectRef, accessTokenEnable the Management API checks (auth, Edge Functions)
apiUrlA self-hosted API gateway, used instead of projectRef
studioUrl, functionsPathWhere self-hosted Edge Functions are read from
source, targetWhat to compare: the source is the truth, the target gets fixed
ignoreSchemasSchemas of your own to leave out
checks.data.tablesTables whose rows are compared and snapshotted
checks.excludeChecks never to run (merged with --skip)
checks.tables, checks.excludeTablesDefault scope for the schema and data checks
checks.migrations.dir, checks.migrations.modeWhere migrations live and how the history check reports
  • Per environment. checks.exclude and checks.schema.timeout can also be set on an environment, and apply when it's the target.
  • .env files. .env files are loaded the Next.js way: .env.{NODE_ENV}.local, .env.local, .env.{NODE_ENV}, .env. Values already in the environment win.
  • Single database. A config with a single environment and no source/target is fine. Use snapshot, clone and restore.
Environment variableDefaultPurpose
SUPAFORGE_DBDIFF_TIMEOUT600Seconds before the schema or data diff gives up
SUPAFORGE_DBDIFF_MEMORY1GMemory limit for @dbdiff/cli (2G, -1 for none)
SUPAFORGE_CONNECT_TIMEOUT15Seconds to wait for a connection
SUPAFORGE_CHECK_CONCURRENCY4Checks run at once. Lower it behind a tight pooler
SUPAFORGE_PROVE_ROWS1000Rows of each table --prove copies to check they survive; 0 checks structure only
SUPAFORGE_PG_BIN—A directory of PostgreSQL client tools (pg_dump, psql), used ahead of PATH — for a server newer than the tools on PATH

Self-hosted Supabase

Set apiUrl to the gateway and accessToken to the service-role key. All checks run.

  • Edge Functions. Self-hosted has no management endpoint for Edge Functions, so set studioUrl (Studio's port, not the gateway's) or functionsPath (the mounted functions directory). The two can be mixed across environments. Studio's functions API is unauthenticated, so don't expose it publicly.
  • Auth config. On self-hosted, auth config is read from GoTrue's settings endpoint, which carries fewer keys and can't be written. Change the deployment's environment instead.

Diffing a clone

A local clone is plain PostgreSQL. Storage, auth, Edge Functions, Vault, Realtime and Supabase's roles have nothing to compare there, so skip those checks:

json
{ "checks": { "exclude": ["storage", "auth", "edge-functions", "vault", "realtime", "roles"] } }

When the source is a clone and the target isn't, diff warns that --apply would push the clone's shape, absences included, onto the target.

CI and exit codes

The GitHub Action runs diff --ci and adds a summary of the drift to the job page:

yaml
- uses: akalsoftware/supaforge-action@v1  env:    DEV_DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}    PROD_DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}

Anywhere else, run the CLI:

bash
npx @akal/supaforge diff --ci
CodeMeaning
0Did what was asked, including when there was nothing to do
1Found drift, declined to act, or something failed or was left out
2Couldn't run: a usage error, or under --ci a check that couldn't finish

--ci fails on critical drift by default. Set the threshold with --fail-on=warning or --fail-on=any.

MCP (AI agents)

SupaForge runs as an MCP server, so an AI agent in your editor can scan for drift and fix it, asking you before anything is written.

[Add to Cursor] [Install in VS Code]

  • Claude Desktop: download the extension for your platform (supaforge-<version>-<platform>.mcpb) from the latest release and open it. It asks for your project directory.

  • Claude Code: install the plugin, which adds the MCP server and a skill for applying fixes safely:

    /plugin marketplace add akalsoftware/claude-plugins/plugin install supaforge@akalsoftware

    or add just the server: claude mcp add supaforge -- npx -y @akal/supaforge mcp

  • Any other client:

    json
    { "mcpServers": { "supaforge": { "command": "npx", "args": ["-y", "@akal/supaforge", "mcp", "--project", "/path/to/project"] } } }

It is listed in the MCP Registry as io.github.akalsoftware/supaforge.

The server exposes these tools:

ToolWhat it doesAnnotation
list_environmentsThe environments in the config, without their credentialsRead-only
diffEvery difference, with the plan sync would runRead-only
get_check_resultOne check's result from the last diff or syncRead-only
syncRuns the plan on the target; prove: true rehearses it on a copy firstDestructive
create_migrationWrites the drift as a migration file, as migrate create doesWrites files
take_snapshotSnapshots an environment to local filesWrites files

diff and sync take the same arguments, so the plan an agent shows you is the plan that runs. Fixes that drop tables or columns are held back unless allowDestructive is set.

It reads supaforge.config.json in the directory given by --project (or the one it starts in), and refuses a configPath from a client unless started with --allow-config-path.

Hooks

ts
import { HookBus, scan, createDefaultRegistry, loadConfig } from '@akal/supaforge'
const bus = new HookBus()bus.on('supaforge.check.after', ({ check, result }) => {  if (result.status === 'drifted') console.log(`Drift in ${check}`)})await scan(createDefaultRegistry(), { config: await loadConfig() }, bus)

Development

bash
cd packages/clinpm installnpm test                 # unit testsnpm run lint             # type-check./bin/dev.js diff        # run from source
SuiteCommandNeeds
Integrationnpm run test:integrationDocker or Podman
Database e2enpm run test:e2eDocker or Podman
Scenariosnpx vitest run -c vitest.scenarios.config.tsDocker or Podman, pg_dump
Supabase e2enpm run test:e2e:supabaseSupabase CLI
Release candidatesscripts/test-release-candidates.sh --dbdiff ../DBDiff --pg-conformance ../pg-conformancePodman or Docker

The release-candidates script builds DBDiff's binary and the npm packages from local checkouts the way a release does, installs SupaForge against them as a user would, and runs every suite above against that install. It tests changes that span the three projects together, before any of them is released.

The scenario suite migrates every case in the @akal/pg-conformance corpus in both directions. It checks the result against the corpus's own state oracle and against --prove.

License

MIT

來源:packages/cli/README.md,提交 8dce28e

工具

6

list_environments

List the environments in supaforge.config.json, and which are the default source and target. Says whether each has the Supabase project details the API-based checks need; never returns credentials.

輸入參數configPath

diff

Compare two Supabase environments and report every difference: schema, RLS, roles and grants, auth, storage, Edge Functions, cron and more. Returns the findings with their SQL, a drift score, and the plan: the statements sync would run, in order, and what it would hold back and why. Writes nothing. Show the plan to the user before calling sync.

輸入參數onlyskipcheckssourcetargetconfigPathallowDestructive

sync

Make the target environment match the source by running the plan diff shows. WRITES TO THE TARGET DATABASE: call diff first, show the user the plan, and call this only once they agree, with the same arguments. SQL fixes run in one transaction and roll back together if any fails. prove=true first rehearses the plan on a throwaway copy of the target and refuses to write if the result would not match the source.

輸入參數onlyskipprovecheckssourcetargetconfigPathallowDestructive

take_snapshot

Capture a point-in-time snapshot of a Supabase environment. Snapshots are stored under .supaforge/snapshots/ and can be used to restore state.

輸入參數configPathenvironment

create_migration

Write the schema difference between source and target as a migration file, as `supaforge migrate create` does: the SQL that brings the target to the source, the grants on what it creates (so it works where new tables are not granted by default), and a DOWN to revert it. Written to the configured migrations directory (supabase/migrations by default). Changes no database.

輸入參數name必填sourcetargetconfigPath

get_check_result

Retrieve the result for one check from the most recent diff or sync call. Returns issues, status, and duration for the named check.

輸入參數check必填

版本歷史

8
  1. v0.0.41最新Nov 6, 2026
  2. v0.0.40Nov 5, 2026
  3. v0.0.39Oct 29, 2026
  4. v0.0.38Oct 22, 2026
  5. v0.0.37Oct 22, 2026
  6. v0.0.35Oct 16, 2026
  7. v0.0.34Oct 15, 2026
  8. v0.0.33Oct 13, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分