This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
364 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules | ||
*.log | ||
logs | ||
test/.tmp | ||
coverage | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
language: node_js | ||
node_js: | ||
- "0.8" | ||
- "0.10" | ||
env: | ||
- TEST_CMD=test | ||
- TEST_CMD=lint | ||
- NODE_ENV=test | ||
before_script: | ||
- npm install -g grunt-cli | ||
- npm install sequelize | ||
- npm i -g grunt-cli | ||
- npm i sequelize | ||
script: | ||
- grunt travis --stack | ||
- grunt validate | ||
- npm run-script coverage | ||
after_script: | ||
- if [ "$TEST_CMD" = 'test' ]; then npm run coveralls; fi | ||
- npm run-script coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: function(migration, DataTypes, done) { | ||
up: function (migration, DataTypes, done) { | ||
// add altering commands here, calling 'done' when finished | ||
done(); | ||
}, | ||
down: function(migration, DataTypes, done) { | ||
down: function (migration, DataTypes, done) { | ||
// add reverting commands here, calling 'done' when finished | ||
done(); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
var Sequelize = require('sequelize'); | ||
var _ = require('lodash'); | ||
|
||
function MigrateTask(opts) { | ||
this._migratorOpts = process.env.NODE_ENV === 'test' ? | ||
{ path: opts.migrations } : /* istanbul ignore next */ | ||
{ path: opts.migrations, logging: console.log }; | ||
|
||
this.db = new Sequelize(opts.database, opts.username, opts.password, opts); | ||
this.migrator = this.db.getMigrator(this._migratorOpts); | ||
} | ||
|
||
MigrateTask.prototype.up = function () { | ||
return this.migrator.migrate(); | ||
}; | ||
|
||
MigrateTask.prototype.down = function () { | ||
return this.migrator.findOrCreateSequelizeMetaDAO() | ||
.then(function (Meta) { | ||
return Meta.find({ order: 'id DESC' }); | ||
}) | ||
.then(function (meta) { | ||
if (!meta) { | ||
return; | ||
} | ||
|
||
return this.db.getMigrator(_.extend(meta.dataValues, this._migratorOpts), true) | ||
.migrate({ method: 'down' }); | ||
|
||
}.bind(this)); | ||
}; | ||
|
||
MigrateTask.prototype.redo = function () { | ||
return this.down() | ||
.then(this.up.bind(this)); | ||
}; | ||
|
||
module.exports = MigrateTask; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var utils = exports; | ||
var path = require('path'); | ||
var _ = require('lodash'); | ||
|
||
utils.lastMigrationId = function (migrator) { | ||
return migrator.findOrCreateSequelizeMetaDAO() | ||
.then(function (Meta) { | ||
return Meta.find({ order: 'id DESC' }); | ||
}) | ||
.then(function (meta) { | ||
return meta ? meta.to : null; | ||
}); | ||
}; | ||
|
||
utils.pad = function (n) { | ||
return n < 10 ? '0' + n : n; | ||
}; | ||
|
||
utils.ts = function () { | ||
var date = new Date(); | ||
|
||
return date.getFullYear().toString() + | ||
utils.pad(date.getMonth() + 1).toString() + | ||
utils.pad(date.getDate()).toString() + | ||
utils.pad(date.getHours()).toString() + | ||
utils.pad(date.getMinutes()).toString() + | ||
utils.pad(date.getSeconds()).toString(); | ||
}; | ||
|
||
utils.optsProvider = function (grunt) { | ||
return function (baseDbPath) { | ||
return _.defaults(grunt.config.get('sequelize.options'), { | ||
config: path.join(baseDbPath, 'config.json'), | ||
migrations: path.join(baseDbPath, 'migrations') | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.