npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

migro

v0.2.3

Published

Lightweight database migration tool

Downloads

8

Readme

migro

js-semistandard-style Build Status npm

Migro is a lightweight database migration tool.

Getting started

Install migro using the following command:

$ npm install --save migro

Or install it globally to use without NPM aliases:

# npm install -g migro

Configuration

Migro can use special file called .migrorc in the root directory of the project. It is a JSON document which stores the following settings:

  • database:
    • <name>:
      • host — database host.
      • port — database port.
      • user — database user (if any).
      • password — database user's password.
      • database — actual database name (overrides <name> above).
  • workingDir: absolute path to the working directory, by default it is equal to the root path of the project.
  • driver: one of the following: pg, mysql.

Commands

$ migro create-version <db> <version>

— creates a new version unders the migrations/db directory.

$ migro create <db> <name>

— creates a new migration under the migrations/<db>/<last possible version>/ directory. Last possible version is determined by using alphabetical sort of the migrations's subdirectories. Convention of calling versions (v1.0.0, 1.0.0, version-1.0.0, etc.) is entirely up to you — as long as plain alphabetical sort provides you with an expected result.

$ migro up <db>

— migrates the db up from the last applied migration to the last possible version.

$ migro up-version <db>

— migrates the db up from the last applied migration using the following logic:

  • if current version doesn't have any unapplied migrations left, then the db is migrated to the latest migration of the next version;
  • if current version has at least one unapplied migration, then the db is migrated up to the latest migration of current version.
$ migro down <db> <number>

— migrates the db from the latest applied migration down number of migrations.

$ migro down-version <db>

— migrates the db down one version, rolling back all migrations from the latest version.

Command line options

-d, --driver

Database driver alias. Supported value is pg only at the moment.

-w, --working-dir

Working directory, which contains the migrations directory. Overrides value from the .migrorc.

Example of usage for PostgreSQL

  1. Create a new .migrorc with the connection options for you database:
{
  "database": {
    "main": {
      "host": "localhost",
      "port": 5432,
      "user": "postgres",
      "password": "S3cur3P@55w0rd"
    }
  }
}

If you database has a long name, you can add separate database field in the connection section, and use top-level name as alias. For example, our main alias from the example above can actually point to MyProjectDatabase database.

  1. Create a new version. Semantic versioning is highly recommended — check it out if you don't know what it is.
$ migro create-version main 0.0.1
Path /my-project/migrations/main/0.0.1 successfully created.

Please note that migrations directory is created automatically if it is not present. You override its placement by adding a workingDir parameter to .migrorc or by passing it with -w argument to migro command.

  1. Create a new migration. It is recommended to give it a meaningful name, so you'll understand what it does just by looking at the file name.
$ migro create main alter-table-Users-add-column-name
Created migration /my-project/migrations/main/0.0.1/20170825225258-alter-table-Users-add-column-name.js
  1. Write code for the migration. The template for migration file mandatory includes two exported methods — up and down, both of which receive single parameter — db, which is database client for your database of choice. Currently migro supports postgres only. The up and down methods are required to be async functions — i.e. they should either be marked as async or return a Promise.

  2. Migrate your database to the latest possible version:

$ migro up main
Running migration for version 0.0.1: 20170825225258-alter-table-Users-add-column-name.js
Done
  1. Rollback migrations for the latest version, as you have found that they contain errors:
$ migro down-version main
Rolling back migration for version 0.0.1: 20170825225258-alter-table-Users-add-column-name.js
Done

That's all, folks!