Skip to main content

db-x / postgres-library/src

postgres-library/src

Interfaces

ExtensionProps

Defined in: postgres-library/src/extension.ts:9

Properties

name

name: string

Defined in: postgres-library/src/extension.ts:11

Extension name, e.g. pgcrypto, uuid-ossp, citext.

user?

optional user?: string

Defined in: postgres-library/src/extension.ts:13

Postgres user to run CREATE EXTENSION as. Defaults to the parent <Postgres user>.

database?

optional database?: string

Defined in: postgres-library/src/extension.ts:15

Database to install into. Defaults to the parent <Postgres database>.

description?

optional description?: string

Defined in: postgres-library/src/extension.ts:17

AI-readable purpose. Surfaced by db-x describe / MCP.


ExtensionOutputs

Defined in: postgres-library/src/extension.ts:20

Indexable

[key: string]: unknown

Properties

name

name: string

Defined in: postgres-library/src/extension.ts:21

installedIn

installedIn: string

Defined in: postgres-library/src/extension.ts:22


PostgresProps

Defined in: postgres-library/src/postgres.tsx:16

Properties

name?

optional name?: string

Defined in: postgres-library/src/postgres.tsx:18

Logical name. Used only to derive the resource id (postgres:<name>).

user?

optional user?: string

Defined in: postgres-library/src/postgres.tsx:20

Connection user. Defaults to the runtime parent's user output if set.

password?

optional password?: string

Defined in: postgres-library/src/postgres.tsx:22

Connection password. Defaults to the runtime parent's password output.

database?

optional database?: string

Defined in: postgres-library/src/postgres.tsx:24

Database name. Defaults to the runtime parent's database output.

protect?

optional protect?: boolean

Defined in: postgres-library/src/postgres.tsx:36

Hard-lock this database's subtree against destructive DDL. When set, db-x apply refuses any destructive change (DROP, ALTER TYPE, …) on this <Postgres> or its children even with --allow-destructive — you must remove protect from the JSX to proceed. This is the deliberate, in-code guard (Terraform prevent_destroy style); --allow-destructive is the weaker global opt-in for unprotected resources.

Enforced by the runtime destructive guard (see findDestructiveViolations). A pre-flight snapshot on protected applies lands with the snapshot driver.

snapshot?

optional snapshot?: "schema" | "full"

Defined in: postgres-library/src/postgres.tsx:51

What a pre-flight snapshot captures before a destructive apply.

schema (default) — structure only. Fast and small on any database, but db-x restore brings back the schema and NOT the rows: a dropped column's data is gone for good. full — structure and row data, so a restore actually undoes the migration. The dump runs inline before the apply and holds a transaction open for its duration, so on a large database this is slow and hostile to vacuum. Deliberate, per-database opt-in.

SQLite and MongoDB have no equivalent knob — their tools always capture everything (see @db-x/snapshot-sqlite, @db-x/snapshot-mongodump).

description?

optional description?: string

Defined in: postgres-library/src/postgres.tsx:53

AI-readable purpose. Surfaced by db-x describe / MCP.


SeedDataProps

Defined in: postgres-library/src/seed.ts:26

Properties

name

name: string

Defined in: postgres-library/src/seed.ts:27

sql

sql: string

Defined in: postgres-library/src/seed.ts:29

Inline SQL. Must be idempotent — see the note above on conflict targets.

user?

optional user?: string

Defined in: postgres-library/src/seed.ts:30

database?

optional database?: string

Defined in: postgres-library/src/seed.ts:31

description?

optional description?: string

Defined in: postgres-library/src/seed.ts:33

AI-readable purpose. Surfaced by db-x describe / MCP.


SeedDataOutputs

Defined in: postgres-library/src/seed.ts:36

Indexable

[key: string]: unknown

Properties

name

name: string

Defined in: postgres-library/src/seed.ts:37

ranAt

ranAt: string

Defined in: postgres-library/src/seed.ts:38


ColumnSpec

Defined in: postgres-library/src/table.tsx:30

Properties

name

name: string

Defined in: postgres-library/src/table.tsx:31

from?

optional from?: string

Defined in: postgres-library/src/table.tsx:38

Previous JSX-side name of this column. When set, the diff emits ALTER TABLE ... RENAME COLUMN "<from>" TO "<name>" instead of adding a fresh column. Required because rename-vs-drop+add is indistinguishable from JSX alone.

type

type: string

Defined in: postgres-library/src/table.tsx:39

primaryKey?

optional primaryKey?: boolean

Defined in: postgres-library/src/table.tsx:40

notNull?

optional notNull?: boolean

Defined in: postgres-library/src/table.tsx:41

unique?

optional unique?: boolean

Defined in: postgres-library/src/table.tsx:42

default?

optional default?: string

Defined in: postgres-library/src/table.tsx:43

description?

optional description?: string

Defined in: postgres-library/src/table.tsx:45

AI-readable purpose for this column.


IndexSpec

Defined in: postgres-library/src/table.tsx:52

Properties

name

name: string

Defined in: postgres-library/src/table.tsx:53

columns

columns: string[]

Defined in: postgres-library/src/table.tsx:54

unique?

optional unique?: boolean

Defined in: postgres-library/src/table.tsx:55

description?

optional description?: string

Defined in: postgres-library/src/table.tsx:57

AI-readable purpose for this index.


TableProps

Defined in: postgres-library/src/table.tsx:68

Properties

name

name: string

Defined in: postgres-library/src/table.tsx:69

user?

optional user?: string

Defined in: postgres-library/src/table.tsx:71

Connection user. Defaults to the parent <Postgres user>.

database?

optional database?: string

Defined in: postgres-library/src/table.tsx:73

Connection database. Defaults to the parent <Postgres database>.

description?

optional description?: string

Defined in: postgres-library/src/table.tsx:75

AI-readable purpose for this table.

children?

optional children?: Child | Child[]

Defined in: postgres-library/src/table.tsx:76


TableDiff

Defined in: postgres-library/src/table.tsx:444

Pure diff function — exported so the upcoming db-x preview / db-x mcp surfaces can render the SQL without running it.

Properties

renames

renames: object[]

Defined in: postgres-library/src/table.tsx:445

from

from: string

to

to: string

additions

additions: ColumnSpec[]

Defined in: postgres-library/src/table.tsx:446

alterations

alterations: object[]

Defined in: postgres-library/src/table.tsx:448

In-place column attribute changes, keyed by the (post-rename) name.

column

column: string

sql

sql: string[]

droppedIndexes

droppedIndexes: string[]

Defined in: postgres-library/src/table.tsx:450

Names of indexes present in prior state but no longer declared.

changedIndexes

changedIndexes: IndexSpec[]

Defined in: postgres-library/src/table.tsx:452

Same name, different columns/unique — dropped and recreated.

droppedColumns

droppedColumns: string[]

Defined in: postgres-library/src/table.tsx:454

Names of columns present in prior state but no longer declared.

sql

sql: string[]

Defined in: postgres-library/src/table.tsx:456

SQL statements in apply order.

destructive

destructive: string[]

Defined in: postgres-library/src/table.tsx:462

The subset of sql that is destructive — drops an object or coerces existing data (ALTER TYPE, DROP INDEX/CONSTRAINT/COLUMN). Metadata-only DROPs (DROP DEFAULT / DROP NOT NULL) are not included.


DatabaseTargetProps

Defined in: postgres-library/src/target.tsx:18

Properties

url

url: string

Defined in: postgres-library/src/target.tsx:20

postgres://user:pass@host:port/database

description?

optional description?: string

Defined in: postgres-library/src/target.tsx:22

AI-readable purpose. Surfaced by db-x describe / MCP.


DatabaseTargetOutputs

Defined in: postgres-library/src/target.tsx:25

Indexable

[key: string]: unknown

Properties

exec

exec: RuntimeExec

Defined in: postgres-library/src/target.tsx:26

host

host: string

Defined in: postgres-library/src/target.tsx:27

port

port: number

Defined in: postgres-library/src/target.tsx:28

user

user: string

Defined in: postgres-library/src/target.tsx:30

Default user — <Postgres user> overrides if set.

password

password: string

Defined in: postgres-library/src/target.tsx:32

Default password — <Postgres password> overrides if set.

database

database: string

Defined in: postgres-library/src/target.tsx:34

Default database — <Postgres database> overrides if set.


DbUserPrivileges

Defined in: postgres-library/src/user.ts:9

Properties

database?

optional database?: string[]

Defined in: postgres-library/src/user.ts:11

Database-level privileges, e.g. ['CONNECT'].

schema?

optional schema?: string[]

Defined in: postgres-library/src/user.ts:13

Schema-level (public) privileges, e.g. ['USAGE'].

table?

optional table?: string[]

Defined in: postgres-library/src/user.ts:15

Table-level privileges applied to ALL TABLES IN SCHEMA public.


DbUserProps

Defined in: postgres-library/src/user.ts:18

Properties

name

name: string

Defined in: postgres-library/src/user.ts:20

Role name to create.

password

password: string

Defined in: postgres-library/src/user.ts:22

Role password.

user?

optional user?: string

Defined in: postgres-library/src/user.ts:24

Superuser to connect as for the CREATE/GRANT. Defaults to the parent <Postgres user>.

database?

optional database?: string

Defined in: postgres-library/src/user.ts:26

Database to grant privileges on. Defaults to the parent <Postgres database>.

privileges?

optional privileges?: DbUserPrivileges

Defined in: postgres-library/src/user.ts:27

description?

optional description?: string

Defined in: postgres-library/src/user.ts:29

AI-readable purpose. Surfaced by db-x describe / MCP.


DbUserOutputs

Defined in: postgres-library/src/user.ts:32

Indexable

[key: string]: unknown

Properties

name

name: string

Defined in: postgres-library/src/user.ts:33

Type Aliases

PostgresState

PostgresState = ResourceState<PostgresProps, PostgresParentOutputs>

Defined in: postgres-library/src/postgres.tsx:167

Variables

Extension

const Extension: JSXComponent<ExtensionProps>

Defined in: postgres-library/src/extension.ts:26


Postgres

const Postgres: JSXComponent<PostgresProps>

Defined in: postgres-library/src/postgres.tsx:56


SeedData

const SeedData: JSXComponent<SeedDataProps>

Defined in: postgres-library/src/seed.ts:42


DatabaseTarget

const DatabaseTarget: JSXComponent<DatabaseTargetProps>

Defined in: postgres-library/src/target.tsx:38


DbUser

const DbUser: JSXComponent<DbUserProps>

Defined in: postgres-library/src/user.ts:37

Functions

pgUrl()

pgUrl(host, user, password, database, port?): string

Defined in: postgres-library/src/postgres.tsx:154

Compose a postgres:// URL from the parts a <Postgres> knows about. Handy when an app service downstream needs DATABASE_URL.

Parameters

host

string

user

string

password

string

database

string

port?

number = 5432

Returns

string


Column()

Column(_props): never

Defined in: postgres-library/src/table.tsx:48

Parameters

_props

ColumnSpec

Returns

never


Index()

Index(_props): never

Defined in: postgres-library/src/table.tsx:60

Parameters

_props

IndexSpec

Returns

never


Table()

Table(props): Element

Defined in: postgres-library/src/table.tsx:79

Parameters

props

TableProps

Returns

Element


buildCreateTable()

buildCreateTable(props): string

Defined in: postgres-library/src/table.tsx:339

Parameters

props
name

string

columns

ColumnSpec[]

Returns

string


columnSql()

columnSql(c): string

Defined in: postgres-library/src/table.tsx:390

Parameters

c

ColumnSpec

Returns

string


buildCreateIndex()

buildCreateIndex(tableName, idx): string

Defined in: postgres-library/src/table.tsx:434

Parameters

tableName

string

idx

IndexSpec

Returns

string


diffTable()

diffTable(tableName, next, nextIndexes, prior): TableDiff

Defined in: postgres-library/src/table.tsx:492

Parameters

tableName

string

next

ColumnSpec[]

nextIndexes

IndexSpec[]

prior
columns

ColumnSpec[]

indexes

IndexSpec[]

Returns

TableDiff