项目作者: soulman-is-good

项目描述 :
PostgreSQL migration/diff/dump simple tool
高级语言: TypeScript
项目地址: git://github.com/soulman-is-good/pg-git.git
创建时间: 2017-03-02T21:45:38Z
项目社区:https://github.com/soulman-is-good/pg-git

开源协议:MIT License

下载


PostgreSQL simple code dumping tool with diff migration

travis npm types

Best used with git :octocat:

This tool was written to help migrate between different servers and to help with distributed development on PostgreSQL.
Tool will automatically download latest Postgres binaries for the platform unless NO_DOWNLOAD env or --no_download flag is specified.
Else tool will try to use system default pg_dump and psql files.

WARNING: This tool uses and bundles:

  • apgdiff v2.6 jar file (requires Java VM)

node >=11.0.0

If you want to override this to yours binaries, e.g. system defaulted, then use envirnoment variables or cli params described below.

Usage

Commonly tool was develop as standalone and to install as dependency to use with npm. But you can also require
it within you project, not much use of it that way though.

  1. const { dump, diff, apply, StringStream } = require('pg-git');
  2. const options = {
  3. user: 'postgres',
  4. password: 'postgres',
  5. database: 'postgres',
  6. host: 'localhost',
  7. port: 5432,
  8. noDownload: true,
  9. };
  10. const newDump = new StringStream('CREATE TABLE public.test(id integer);');
  11. // dump current database, make a diff and apply
  12. dump(options)
  13. .then(dumpStream => diff(options, dumpStream, newDump))
  14. .then(diffStream => apply(options, diffStream))
  15. .catch(console.error);

Or you can install tool globaly (or localy and use with npm run …)

  1. npm i -g pg-git

And use it in your project

Usage

  1. pgit [options] <command>
  2. Commands:
  3. commit - Create new dump
  4. migrate - Make a diff with dump file and apply it to database
  5. Options:
  6. --user <USERNAME> - database user
  7. --password <PASSWORD> - database password
  8. --host <HOST> - pg host
  9. --port <PORT> - database port
  10. --dumpname <dumpname> - dump file name. default: dump.sql
  11. --pgversion <version> - postgres version to use. Specify exact version or only part else latest will be taken. E.g. 10 or 9.5 or 9.4.21
  12. --psql <path> - path to psql binary
  13. --pg_dump <path> - path to pg_dump binary
  14. --no_download <any> - do not download binaries from external resource

Example

  1. pg-git --user postgres --password postgres --host 127.0.0.1 --port 5432 commit my_database

Environment variables

  1. PGUSER - Postgres user
  2. PGHOST - Postgres host
  3. PGDATABASE - Postgres database name
  4. PGPASSWORD - Postgres password for user
  5. PGVERSION - postgres version to use. Specify exact version or only part else latest will be taken. E.g. 10 or 9.5 or 9.4.21
  6. PSQL_PATH - Absolute path to your psql binary file
  7. PG_DUMP_PATH - Absolute path to yout pg_dump binary file
  8. NO_DOWNLOAD - do not download binaries from external resource