Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

extract

Apply SQL to a PGlite instance, extract the schema, and output it as JSON.

Usage

pgmagmig extract --from-sql schema.sql
pgmagmig extract --from-database postgres://localhost/mydb
pgmagmig extract --from-migrations-dir ./migrations

Options

OptionDescription
--from-sql <files...>SQL files to apply (order matters)
--from-json <file>JSON schema file
--from-emptyEmpty schema
--from-database <url>Live database (read-only extraction)
--from-migrations-dir <path>Apply migration files to PGlite

Exactly one --from-* option is required. See Schema Sources.

Output

JSON representation of the database schema, written to stdout. The output includes tables (with columns and constraints), indexes, views, functions, triggers, enums, sequences, schemas, and extensions.

Example

pgmagmig extract --from-sql schema.sql > schema.json