Skip to content

seveibar/pg-schema-dump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node PG Schema Dump pg-schema-dump

Warning

If you're upgrading from version 1, it's likely there are many breaking changes. In Version 2 we switched off libpq-query so that we could have node-native query parsing/generation.

This is an alternative to pg_dump written in node. You can use this to get all the SQL to recreate a schema or a diretory representing a schema, which is awesome for viewing database changes.

Installation

npm add -D pg-schema-dump

Usage

schema.sql dumping

# By default, pg-dump knows POSTGRES_HOST, DATABASE_URL, etc.
pg-schema-dump dump

# Dump schema.sql to stdout for public schema on default database "postgres"
pg-schema-dump dump -h localhost -U postgres

# With postgres URL
pg-schema-dump dump psql://user:1234@localhost:5432/my_db

Tree Dumping

"Tree Dumps" are great for code reviews. They use a directory structure to easily diff database changes. For example, a table definition goes into a file in <schema>/<table>/table.sql. This makes it easy to find and examine different parts of your database in a structured way.

pg-schema-dump dump-tree /path/to/dir

# You can use the same environment variables or specify the host etc.
pg-schema-dump dump-tree -h localhost -U postgres /path/to/dir

As a Library

import { getSchemaSQL, getTree } from "pg-schema-dump"

// Uses environment variables, DATABASE_URL etc.
await getSchemaSQL({
  schemas: ["public"],
})

await getTree({
  schemas: ["public"],
})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published