Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Last active January 4, 2016 12:32
Show Gist options
  • Save thebergamo/5bd46863a75b8961d1de to your computer and use it in GitHub Desktop.
Save thebergamo/5bd46863a75b8961d1de to your computer and use it in GitHub Desktop.
'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();
}
#!/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!"
'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