postgres-meta
CLAUDE.md1.3k starsChanged 3 months agoApache-2.0View on GitHub
postgres-meta is a RESTful API for managing PostgreSQL databases. It provides a normalized interface over the PostgreSQL system catalog, exposing database objects (tables, columns, functions, etc.) through a Fastify-based REST API. The library can be used both as a standalone server and as an npm package. The dev server uses nodemon with ts-node/esm loader and pipes output through pino-pretty for readable logs. Build process: TypeScript compilation (tsc) + copying src/lib/sql/*.sql files to dist/lib/sql/ via cpy-cli. Tests use Vitest with snapshot…
Trending
Quiet since September.about the whole repository
Who's talking about supabase/postgres-meta
- supabase/supabase“Poor BigInt support”GitHub · Mar 29, 2024 · 11 reactions
- supabase/supabase-js“Allow parsing date and time types as JS `Date`”GitHub · Nov 5, 2024 · 7 reactions
- supabase/cli“Allow insertion of custom types for 'Json' type with the 'gen types typescript' command”GitHub · Nov 9, 2022 · 2 reactions
- supabase/cli“generating typescript type fails when there is certain special chars in password”GitHub · Aug 16, 2022 · 2 reactions
- supabase/supabase-js“feat(supabase): export DatabaseWithoutInternals utility type”GitHub · Dec 9, 2025 · 1 reactions
The biggest 5 of 21 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 21
Talked about on GitHub (21 times).
On GitHub · 21
- Mar 29, 2024Poor BigInt support — supabase/supabase11 reactions · 13 comments
- Nov 5, 2024Allow parsing date and time types as JS `Date` — supabase/supabase-js7 reactions · 3 comments
- Nov 9, 2022Allow insertion of custom types for 'Json' type with the 'gen types typescript' command — supabase/cli2 reactions · 2 comments
- Aug 16, 2022generating typescript type fails when there is certain special chars in password — supabase/cli2 reactions · 3 comments
- Dec 9, 2025feat(supabase): export DatabaseWithoutInternals utility type — supabase/supabase-js1 reaction · 2 comments
16 more on GitHub
- Oct 7, 2025feat(postgrest): add embeded functions type inference — supabase/supabase-js1 reaction · 2 comments
- Mar 30, 2025feat(types): add inference for embeded joins by functions — supabase/postgrest-js1 reaction · 3 comments
- Nov 28, 2023feat: pg-meta 0.75.0 — supabase/cli1 reaction · 1 comment
- Sep 29, 2022Chore/improve grid cell editors — supabase/supabase1 reaction · 2 comments
- Sep 16, 2026ci(postgrest-typegen): drop the nightly parity job against postgres-meta — supabase/sdk0 reactions · 1 comment
- Sep 4, 2026Bump @supabase/postgres-meta from 0.98.0 to 0.99.0 — change-engine/battery-cable0 reactions
- Aug 31, 2026feat(postgrest-typegen): formatter hook, oxfmt default, concurrent introspection — supabase/sdk0 reactions · 1 comment
- Aug 18, 2026Bump @supabase/postgres-meta from 0.97.0 to 0.98.0 — change-engine/battery-cable0 reactions
- Aug 17, 2026Bump @supabase/postgres-meta from 0.96.8 to 0.97.0 — change-engine/battery-cable0 reactions
- Aug 10, 2026Bump @supabase/postgres-meta from 0.96.6 to 0.96.8 — change-engine/battery-cable0 reactions
- May 18, 2026Bump @supabase/postgres-meta from 0.96.5 to 0.96.6 — change-engine/battery-cable0 reactions
- May 4, 2026Bump @supabase/postgres-meta from 0.96.4 to 0.96.5 — change-engine/battery-cable0 reactions
- Mar 3, 2026feat(studio): wrap table creation in single atomic transaction — greptileai/supabase-mirror0 reactions · 1 comment
- Mar 10, 2025chore(deps)(deps): update @supabase/postgres-meta requirement from ^0.10.0 to ^0.86.3 in /src/backend in the supabase group across 1 directory — businessintelli/hotgigs-iz2pxa0 reactions · 1 comment
- Mar 1, 2024Bump @supabase/postgrest-js from 1.9.0 to 1.12.0 — mdhira-ai/nodejs0 reactions
- Sep 24, 2022Add postgres-meta — mgramin/awesome-db-tools0 reactions
The file
We split this CLAUDE.md into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 87
All methods return PostgresMetaResult<T> = { data: T | null, error: Error | null }
- Distinctive: line 183
Add test case reproducing the bug
- Very specific: line 185
Run npm run test:update (adds -u flag to vitest)
- Very specific: line 187
Remove -u flag before committing (or use npm run test directly)
- Very specific: line 205
Import statements use .js extension (TypeScript convention for ESM)
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Overview
postgres-meta is a RESTful API for managing PostgreSQL databases. It provides a normalized interface over the PostgreSQL system catalog, exposing database objects (tables, columns, functions, etc.) through a Fastify-based REST API. The library can be used both as a standalone server and as an npm package.
Development Commands
Development Server
npm run dev # Start dev server with Docker DB (auto-cleans on exit)
npm run dev:code # Start dev server without DB setup (if DB already running)The dev server uses nodemon with ts-node/esm loader and pipes output through pino-pretty for readable logs.
Building
npm run build # Compile TypeScript + copy SQL files to dist/
npm run clean # Remove dist/ and tsconfig.tsbuildinfo
npm run check # Type-check without emitting filesBuild process: TypeScript compilation (tsc) + copying src/lib/sql/*.sql files to dist/lib/sql/ via cpy-cli.
Testing
npm test # Full test: db:clean -> db:run -> test:run -> db:clean
npm run test:run # Run tests only (DB must be running)
npm run test:update # Update test snapshots (runs db:clean -> db:run first)Tests use Vitest with snapshot testing. Test files are split between test/lib/ (library tests) and test/server/ (API tests). All tests import from test/index.test.ts which orchestrates test execution.
Important: Tests require Docker. The test DB is managed via test/db/docker-compose.yml and runs on port 5432. Tests run sequentially (maxConcurrency: 1) and use pool: 'forks' to avoid memory issues.
Database Management
npm run db:run # Start test DB in Docker (detached, with healthcheck)
npm run db:clean # Stop and remove test DB containersType Generation
npm run gen:types:typescript # Generate TypeScript types from DB schema
npm run gen:types:python # Generate Python types (Pydantic models)
npm run gen:types:go # Generate Go types
npm run gen:types:swift # Generate Swift types (beta)
# With custom DB connection:
PG_META_DB_URL=postgresql://... npm run gen:types:typescriptType generation is controlled by PG_META_GENERATE_TYPES env var and runs the server in special mode (exits after generating types to stdout).
Code Quality
npm run format # Format code with PrettierArchitecture
Two-Layer Design
- Library Layer (
src/lib/): Core PostgreSQL introspection logicPostgresMeta.ts: Main class that aggregates all metadata managersPostgresMeta*.ts: Individual managers for each database object type (columns, tables, functions, etc.)sql/*.sql.ts: SQL query templates for fetching metadata from system catalogsParser.ts: SQL parsing, formatting, and deparsing (uses pgsql-parser)db.ts: Connection pooling and query execution with error handling
- Server Layer (
src/server/): REST API built with Fastifyserver.ts: Entry point, handles normal server mode + type generation modeapp.ts: Main Fastify app with routes, CORS, Swagger docsadmin-app.ts: Admin server (runs on PG_META_PORT + 1) for metricsroutes/*.ts: REST endpoints mapping to library methodsroutes/generators/*.ts: Type generation endpoints backed by@supabase/postgrest-typegen
Object Manager Pattern
Each PostgreSQL object type has a dedicated manager class following this pattern:
PostgresMetaTables,PostgresMetaColumns,PostgresMetaFunctions, etc.- Each manager has methods:
list(),retrieve(),create(),update(),remove() - Managers compose SQL from
src/lib/sql/*.sql.tstemplates - All methods return
PostgresMetaResult<T>={ data: T | null, error: Error | null }
SQL Query Organization
SQL queries are defined in src/lib/sql/*.sql.ts as TypeScript template literals:
- Queries use
pg-formatfor safe parameterization - Complex queries join against
pg_catalogandinformation_schema - Build process copies SQL files to
dist/lib/sql/for runtime access
Connection Pooling
- Uses custom
@supabase/pgfork (v0.0.3) instead of standardpg - Connection pool initialized in
db.tsviainit(config) - Pool configuration supports:
connectionTimeoutMillis: Connection timeout (default 15s)query_timeout: Query timeout (default 55s)maxResultSize: Max result size in bytes (default 2GB, configurable viaPG_META_MAX_RESULT_SIZE_MB)- SSL configuration via
PG_META_DB_SSL_ROOT_CERT
- Custom error handling for
RESULT_SIZE_EXCEEDEDerrors - Pool auto-reconnects on connection errors by calling
pool.end()and reinitializing
Error Handling
Database errors are formatted to mimic psql output:
- Includes severity, error code, message, line number, position marker
- Position calculation accounts for injected
SET statement_timeoutprefix - Returns structured errors:
{ code, message, formattedError, position, detail, hint }
Type Generation
Type generation (npm run gen:types:*) works by:
- Connecting to a database (test DB or custom via
PG_META_DB_URL) - Introspecting schemas, tables, columns, relationships, functions, and types via
@supabase/postgrest-typegen'sintrospect()(wrapped bysrc/lib/generators.ts) - Passing the metadata to the package's language generators (
generateTypescript,generateGo,generateSwift,generatePython) - Generators output type definitions to stdout
Environment variables:
PG_META_GENERATE_TYPES: Language (typescript, python, go, swift)PG_META_GENERATE_TYPES_INCLUDED_SCHEMAS: Comma-separated schemas to includePG_META_GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS: Enable 1:1 relationship detectionPG_META_POSTGREST_VERSION: PostgREST version for TypeScript template compatibility
Environment Variables
Required for server operation:
PG_META_HOST=0.0.0.0 # Server host
PG_META_PORT=8080 # Server port (admin runs on +1)
PG_META_DB_HOST=localhost # PostgreSQL host
PG_META_DB_NAME=postgres # Database name
PG_META_DB_USER=postgres # Database user
PG_META_DB_PORT=5432 # PostgreSQL port
PG_META_DB_PASSWORD=postgres # Database password (or use CRYPTO_KEY for secrets)
PG_META_DB_SSL_MODE=disable # SSL mode (disable, require, verify-full, etc.)Alternative connection:
PG_META_DB_URL=postgresql://... # Full connection string (overrides individual params)Performance tuning:
PG_CONN_TIMEOUT_SECS=15 # Connection timeout (default: 15)
PG_QUERY_TIMEOUT_SECS=55 # Query timeout (default: 55)
PG_META_MAX_RESULT_SIZE_MB=20 # Max query result size in MB (default: 2048MB)
PG_META_MAX_BODY_LIMIT_MB=3 # Max request body size in MB (default: 3MB)
PG_META_SHUTDOWN_GRACE_PERIOD_SECS=10 # Shutdown wait on in-flight work before force-exit (default: 10)TypeScript generation on a worker thread (opt-in):
PG_META_FORMAT_IN_WORKER=true # Generate TypeScript types on a worker thread (default: false)
PG_META_FORMAT_POOL_SIZE=1 # Worker threads used for generation (default: 1)
PG_META_FORMAT_MAX_QUEUE=20 # Max generation calls in flight before returning 503 (default: 20)
PG_META_FORMAT_TIMEOUT_SECS=60 # Per-generation timeout (default: 60)
PG_META_FORMAT_IDLE_TIMEOUT_SECS=30 # Idle time before a worker exits (default: 30)generateTypescript is CPU-bound and synchronous: on a large schema it blocks
the event loop and the server cannot answer anything else, health checks
included. Formatting is the bulk of it (oxfmt since postgrest-typegen 0.2.0,
much faster than the prettier it replaced but still synchronous) and the string
building ahead of it costs too, so PG_META_FORMAT_IN_WORKER=true moves the
whole call to a worker thread (src/server/format-pool.ts). Metadata
crosses the thread boundary as a structured clone, which is plain JSON and does
not measurably change wall-clock time. Always off during type generation
(PG_META_GENERATE_TYPES), which generates once and exits.
The env vars keep their PG_META_FORMAT_* names from when the worker formatted
only, so existing deployments do not need reconfiguring.
Testing Notes
Snapshot Testing
Tests use Vitest inline snapshots (toMatchInlineSnapshot). When fixing bugs:
- Add test case reproducing the bug
- Fix the bug
- Run
npm run test:update(adds-uflag to vitest) - Review git diff of snapshots -
idfield changes are expected - Remove
-uflag before committing (or usenpm run testdirectly)
Test Structure
test/lib/*.ts: Direct library tests usingpgMetainstancetest/server/*.ts: HTTP API tests using Fastify test utilstest/index.test.ts: Main entry point that imports all test modulestest/db/: Docker Compose config for test database with SSL enabled
Custom Database Connection
To test against a different database:
PG_META_DB_URL=postgresql://user:pass@host:port/dbname npm run dev:codeModule System
This project uses ESM (ES Modules):
"type": "module"in package.json- Import statements use
.jsextension (TypeScript convention for ESM) - Node >=20 required
- ts-node runs with
--loader ts-node/esmflag - Uses import attributes for JSON:
import pkg from '#package.json' with { type: 'json' }
Special Imports
The #package.json import is defined in package.json imports field:
"imports": {
"#package.json": "./package.json"
}This allows importing package.json metadata in ESM without path resolution issues.
OpenAPI Documentation
Generate OpenAPI spec:
npm run docs:export > openapi.jsonUses Fastify's @fastify/swagger plugin. Routes define schemas using @sinclair/typebox for automatic OpenAPI generation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

