Coder Social home page Coder Social logo

sails-db-migrate's Introduction

sails-db-migrate

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
};

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

sails-db-migrate's People

Contributors

chadxz avatar clintonpaquin avatar leedm777 avatar tobalsgithub avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.