Skip to main content

Quickstart (managed DB)

For an existing managed Postgres (RDS, Cloud SQL, Supabase, …), point <DatabaseTarget url={...}> at its postgres:// URL. The schema below is identical to the Docker quickstart — only the connection URL changes.

Experimental

DB-X is an early prototype — don't point it at a database you care about. Build the CLI first (see Install); db-x preview/apply/destroy run today. Snapshot / restore shown below are on the roadmap.

Schema file

/** @jsxRuntime automatic */
/** @jsxImportSource @db-x/runtime */

import {
Column,
DatabaseTarget,
Postgres,
Table,
} from '@db-x/postgres-library';

const dbUrl = process.env.DATABASE_URL!;

export default (
<DatabaseTarget url={dbUrl}>
<Postgres name="todos-db">
<Table name="todos">
<Column name="id" type="serial" primaryKey />
<Column name="title" type="text" notNull />
<Column name="done" type="boolean" notNull default="false" />
</Table>
</Postgres>
</DatabaseTarget>
);

Preview against the live database

DATABASE_URL="postgres://user:pass@host:5432/todos_db" \
pnpm db-x preview ./dbx.tsx

The output tells you exactly what DDL db-x apply would run against the live database — and, once shipped, what Shadow-DB preview reports about lock impact and timings.

Apply

DATABASE_URL="postgres://user:pass@host:5432/todos_db" \
pnpm db-x apply ./dbx.tsx

Runs the DDL against the live database and persists the new state to .dbx/state.json.

Coming soon

On the roadmap (v0.1), db-x apply will take a snapshot first so you can roll back in seconds:

pnpm db-x snapshot create --label "before todos.priority" # planned
pnpm db-x apply ./dbx.tsx
pnpm db-x restore --to "before todos.priority" # planned

Next steps