New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ovotech/pg-sql-migrate

Package Overview
Dependencies
Maintainers
77
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ovotech/pg-sql-migrate

run migration scripts incrementally using postgres

  • 1.0.3
  • npm
  • Socket score

Version published
Weekly downloads
663
decreased by-40.91%
Maintainers
77
Weekly downloads
 
Created
Source

Postgres migration tool with plain sql

A very small library for running sql migrations with postgres. It differs from the numerous other libs in this domain by being very minimal, using only raw timestamped sql files. No "down" migrations are provided by design, as that is usually a bad idea in production anyway.

Using with CLI

yarn add @ovotech/pg-sql-migrate

add a configuration file, which by default is ./pg-sql-migrate.config.json to configure the connection:

{
  "client": "postgresql://postgres:dev-pass@0.0.0.0:5432/postgres"
}

and place some migration files, with .pgsql extension. into your migrations folder. Like

migrations
|-<timestamp>_somename-1.pgsql
|-<timestamp>_somename-2.pgsql

Then in your code you can:

import { migrate } from '@ovotech/pg-sql-migrate';

const results = await migrate();

You can choose a different location for the config file, or to just input its contents direclty:

import { migrate } from '@ovotech/pg-sql-migrate';

const results = await migrate('my_config.json');

const results = await migrate({
  client: 'postgresql://postgres:dev-pass@0.0.0.0:5432/postgres',
  // Custom table location
  table: 'my_table',
  // Custom directory for migration files
  dir: 'migrations_dir',
});

Low level node streams

If you want to use the underlying streams themselves you can do so:

import { MigrationsReadable, MigrationsWritable } from '@ovotech/pg-sql-migrate';
import { Client } from 'pg';

const pg = new Client('postgresql://postgres:dev-pass@0.0.0.0:5432/postgres');

// Read the migration files and stream the migrations that have not yet run.
const migrations = new MigrationsReadable(pg, 'migrations_table', 'migrations_dir');

// Execute the migrations with the pg client, and save their status to the migrations table
const sink = new MigrationsWritable(pg, 'migrations_table');

migrations.pipe(sink);

Running the tests

You can run the tests with:

yarn test

Coding style (linting, etc) tests

Style is maintained with prettier and tslint

yarn lint

Deployment

To deploy a new version, push to master and then create a new release. CircleCI will automatically build and deploy a the version to the npm registry. All package versions are synchronized, but it will only publish the versions of the packages that have changed.

Contributing

Have a bug? File an issue with a simple example that reproduces this so we can take a look & confirm.

Want to make a change? Submit a PR, explain why it's useful, and make sure you've updated the docs (this file) and the tests (see test/integration.spec.ts).

Responsible Team

  • OVO Energy's Boost Internal Tools (BIT)

License

This project is licensed under Apache 2 - see the LICENSE file for details

FAQs

Package last updated on 17 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc