Last active
January 4, 2016 12:32
-
-
Save thebergamo/5bd46863a75b8961d1de to your computer and use it in GitHub Desktop.
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
'use strict'; | |
module.exports = { up, down }; | |
function up (db) { | |
const User = require('../src/shared/user/model')(db.sequelize, db.Sequelize); | |
return User.sync(); | |
}; | |
function down (db) { | |
const User = require('../src/shared/user/model')(db.sequelize, db.Sequelize); | |
return User.drop(); | |
} |
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
#!/bin/sh | |
# script/migration: Execute the migration script to update or downgrade database. | |
set -e | |
cd "$(dirname "$0")/.." | |
echo "===> Migrating "$1" DB..." | |
node src/core/migration.js $1 | |
echo "==> App is now ready to go!" |
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
'use strict'; | |
require('dotenv').load(); | |
const Umzug = require('umzug'); | |
const db = require('./database'); | |
// Instantiate Umzug | |
let options = { | |
storage: 'sequelize', | |
storageOptions: { | |
sequelize: db.sequelize, | |
modelName: 'MigrationSchema', | |
tableName: 'MigrationTable' | |
}, | |
logging: false, // TODO: Create new logger to migration function receive a message parameter. | |
upName: 'up', | |
downName: 'down', | |
migrations: { | |
params: [db], | |
path: 'migrations', | |
pattern: /(migrations.js)$/ | |
} | |
}; | |
const umzug = new Umzug(options); | |
const type = process.argv[2]; | |
run (type); | |
function run (type) { | |
type = type === 'down' ? 'down' : 'up'; | |
return umzug[type]() | |
.then((migrations) => { | |
migrations.map((migration) => { | |
console.log('Executed: ', migration.file); | |
}); | |
}) | |
.then(() => { | |
console.log('Migration Success'); | |
process.exit(); | |
}) | |
.catch((err) => { | |
console.log('Error executing migrations: ', err); | |
process.exit(1); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment