├── package.json ├── README.md ├── .gitignore ├── LICENSE └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-sequelize", 3 | "version": "0.0.2", 4 | "description": "Helper for running sequelize migrations", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/sequelize/gulp-sequelize.git" 9 | }, 10 | "author": "Trey Thomas ", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | gulp-sequelize 2 | ============== 3 | 4 | Gulp tasks for sequelize. 5 | 6 | [![NPM](https://nodei.co/npm/gulp-sequelize.png)](https://npmjs.org/package/gulp-sequelize) 7 | 8 | ### Install 9 | ``` 10 | npm install --save-dev gulp-sequelize 11 | ``` 12 | 13 | ### Usage 14 | 15 | ```js 16 | var gulpSequelize = require('gulp-sequelize')(sequelize); 17 | 18 | gulp.task('up', gulpSequelize.up); 19 | 20 | gulp.task('down', gulpSequelize.down); 21 | 22 | gulp.task('pending', gulpSequelize.pending); 23 | 24 | gulp.task('executed', gulpSequelize.executed); 25 | ``` 26 | 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 sequelize 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Umzug = require('umzug'); 4 | var _ = require('lodash'); 5 | 6 | module.exports = function gulpSequelize(sequelize, options) { 7 | options = _.merge({ 8 | storage: 'sequelize', 9 | storageOptions: { 10 | sequelize: sequelize 11 | }, 12 | logging: function(msg) { 13 | console.log(msg); 14 | }, 15 | migrations: { 16 | wrap: function(migrationFn) { 17 | return function() { 18 | return migrationFn(sequelize.queryInterface, sequelize.Sequelize); 19 | }; 20 | } 21 | }, 22 | }, options); 23 | 24 | var umzug = new Umzug(options); 25 | 26 | return { 27 | up: function() { 28 | return umzug.up() 29 | .then( function() { 30 | sequelize.close(); 31 | }); 32 | }, 33 | 34 | down: function() { 35 | return umzug.down() 36 | .then( function() { 37 | sequelize.close(); 38 | }); 39 | }, 40 | 41 | pending: function() { 42 | return umzug.pending() 43 | .each( function(migration) { 44 | console.log(migration.file); 45 | }) 46 | .then( function() { 47 | sequelize.close(); 48 | }); 49 | }, 50 | 51 | executed: function() { 52 | return umzug.executed() 53 | .each( function(migration) { 54 | console.log(migration.file); 55 | }) 56 | .then( function() { 57 | sequelize.close(); 58 | }); 59 | }, 60 | }; 61 | }; 62 | --------------------------------------------------------------------------------