Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postgrate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgrate

A simple, intuitive postgres migration tool for [node-postgres](https://node-postgres.com/)!

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by25%
Maintainers
1
Weekly downloads
 
Created
Source

Postgrate 🐘

A simple, intuitive postgres migration tool for node-postgres!

SQL is awesome. There are a lot of great ORMs out there, but this package is for those who prefer raw SQL!

Postgrate provides utility commands to generate raw .sql migration files and corresponding rollback files. Migrations are executed transactionally. The goal is to enable developers to more efficiently create and manage migrations written in .sql.

Installation

$ yarn add postgrate

Basic Usage

After insallation, make sure that you have a .env file that looks like this:

PG_DATABASE_URL=<your postgres connection url>

Once that's done, you can run the following command:

$ postgrate init

*Note: in the current release of this package, this command is somewhat trivial as running the first migration will perform initialization steps if they haven't already been completed. Note that in all cases, you must run the run command at least once before running the rollback command, otherwise you will encounter an error. The init command has been included to accomodate future plans to support a configuration file.*

To create a migration, run:

$ postgrate make <your-migration-name>

In the root of your project directory, you should now see the following:

db
 |_migrations
    |_<timestamp>-<your-migration-name>.sql
 |_rollbacks
     |_rb-<timestamp>-<your-migration-name>.sql

After you write your migration in the .sql migration file, run:

$ postgrate run

You should see the following output:

     Migration <timestamp>-<your-migration-name>.sql [id: 1] has been executed 🚀

Things to Note

This package will create a table in your database called migrations. While we hope to make this configurable in the future, for now this package will confilct with any concurrently used package that follows a similar strategy.

Commands

To view a list of commands, run:

$ postgrate help

You should get the following output:

📖 Postgrate CLI 📖
Usage: postgrate <command> [options]

Commands:
  -h,  help      Show help
  -i,  init      Initialize postgrate
  -l,  list      List all migrations
  -m,  make      Create a migration file
  -r,  run       Run all pending migrations
  -rb, rollback  Rollback a migration

Examples:
  $ postgrate -h
  $ postgrate -i
  $ postgrate -l
  $ postgrate -m create-users-table
  $ postgrate -r
  $ postgrate -rb 1

FAQs

Package last updated on 29 Nov 2023

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