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

sails-db-migrate

v1.5.0

Published

db-migrate integration for sails.js

Downloads

522

Readme

sails-db-migrate

devDependency Status peerDependency Status

db-migrate integration for Sails.js. This is a fairly simple wrapper, which provides grunt tasks for running and creating migrations. It also extracts the database configuration from the Sails config, so you don't have to duplicate you config in a database.json file.

Supports Sails 0.10.x.

Setup

Installation is very typical.

$ npm install --save sails-db-migrate

You may also have to explicitly install your database driver. Normallys it's installed under sails-{postgresql,mysql}, but that won't be found outside of that package.

$ npm install --save pg # or mysql

You need to setup config/migrations.js to name the connection which you will use to run migrations.

// config/migrations.js
module.exports.migrations = {
  // connection name matches a field from config/connections.js
  connection: 'somePostgresqlServer' // or MySQL
};

Optionally, you can specify in the config file the name of the database table to be used to track migrations (defaults to migrations), the directory to use for migrations (defaults to migrations), and whether to create a coffeescript file for the migrations instead of javascript file (defaults to false).

// config/migrations.js
module.exports.migrations = {
  // connection name matches a field from config/connections.js
  connection: 'somePostgresqlServer', // or MySQL
  table: 'sails_migrations',
  migrationsDir: 'sails_migrations',
  coffeeFile: true
};

You'll also need to setup tasks/register/dbMigrate.js to add the db:migrate tasks to grunt.

// tasks/register/dbMigrate.js
module.exports = require('sails-db-migrate').gruntTasks;

Usage

Help

Help can be found by running grunt db:migrate.

$ grunt db:migrate

Creating migrations

You create migrations using the grunt db:migrate:create

$ grunt db:migrate:create --name add-some-fooz

+ db-migrate create add-some-fooz
[INFO] Created migration at /Users/dlee/prj/test/migrations/20140829025723-add-some-fooz.js

Done, without errors.

You can edit your new migration file. This is fully documented in the db-migrate docs.

Running migrations

Migrations can be run up or down. To run only a certain number of migrations, specify the --count flag.`

$ grunt db:migrate:up
Running "db:migrate:up" (db:migrate) task
+ db-migrate up
[INFO] Processed migration 20140829025723-add-some-fooz
[INFO] Done

Done, without errors.

$ grunt db:migrate:down --count 2
Running "db:migrate:down" (db:migrate) task
+ db-migrate down --count 2
[INFO] Processed migration 20140829025723-add-some-fooz
[INFO] Processed migration 20140829025008-init
[INFO] Done

Done, without errors.

To specify your own migrations directory, use --migrations-dir.

$ grunt db:migrate:up --migrations-dir=migrations-special

Debugging

Normally, migrations load Sails with a log level of silent, since you usually don't need it. Sometimes, however, Sails will fail to load, and some debug output would be nice.

You can set the LOG_LEVEL environment variable to turn up sails logging for the migrations

$ LOG_LEVEL=debug grunt db:migrate:up

Patches Welcome

If you'd like to contribute to sails-db-migrate, start by looking at some of the open issues in the issue tracker.