How to use db-migrate - 10 common examples

To help you get started, we’ve selected a few db-migrate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ostdotcom / ost-view / helpers / db_migrate.js View on Github external
json['stage'] = db_config;
json['dev'] = db_config;


json = JSON.stringify(json);
try {
	fs.writeFileSync('database.json', json, 'utf8');
}

catch(error) {
	throw error;
	process.exit(1);
}

// The next step is to get a new instance of DBMigrate
var dbmigrate = DBMigrate.getInstance(true);

// next we call the migrations
console.log(db_config.database);

dbmigrate.reset(() => {
  dbmigrate.up(() => {
     console.log('Migration Successful');
  } );
});
github ostdotcom / ost-view / executables / db_migrate.js View on Github external
const createMigration = function (name) {

  //Getting chain ID of first config. It is irrelevent in case of mirgration creation.
  if (!core_config.getAllChainIDs()[0]) {
    logger.error('Config of chain not defined');
    process.exit(0);
  }

  initDBConfigFile(core_config.getAllChainIDs()[0]);
  logger.log("Migration name:", name);

  // The next step is to get a new instance of DBMigrate
  var dbmigrate = DBMigrate.getInstance(true);

  dbmigrate.create(name, null, function (err) {
    if (err) {
      logger.error(err);
      process.exit(1);
    }
    logger.log('Migration created Successfully');
  });
};
github birkir / prime / packages / prime-core / src / db / init.ts View on Github external
// tslint:disable no-require-imports no-var-requires no-console
require('dotenv').config();

import * as DBMigrate from 'db-migrate';
import * as path from 'path';
import { sequelize } from '../sequelize';

const dbmigrate = DBMigrate.getInstance(true, {
  cwd: path.join(__dirname + '/../..'),
});

if (process.env.NODE_ENV !== 'production') {
  dbmigrate.silence(true);
}

(async () => {
  process.stdout.write('Migrating database... ');
  const migrations = await dbmigrate.up();
  console.log('done (' + (migrations ? migrations.length : '0') + ' migrations)');

  process.stdout.write('Syncing sequelize... ');
  await sequelize.sync();
  console.log('done');
github ripple / ripple-rest / db / migrations / 20140123173245-outgoing-transactions.js View on Github external
var dbm = require('db-migrate');
var type = dbm.dataType;

exports.up = function(db, callback) {
  db.createTable('outgoing_transactions', {

    /* Auto-generated */
    created_at: {type: 'timestamp'},
    updated_at: {type: 'timestamp'},

    /* Added initially */
    initial_hash: {type: 'text', primaryKey: true},
    submitted_at_ledger: {type: 'int'},
    src_address: {type: 'text'},
    tx_type: {type: 'text'},
    tx_state: {type: 'text'}, // Updated after submission

    /* Added after submission */
github ripple / ripple-rest / db / migrations / 20140116225343-notifications.js View on Github external
var dbm = require('db-migrate');
var type = dbm.dataType;

exports.up = function(db, callback) {
  db.createTable('notifications', {
    /* Auto-generated */
    createdAt: {type: 'timestamp'},
    updatedAt: {type: 'timestamp'},

    /* rippled fields */
    '"txHash"': {type: 'text', primaryKey: true},
    txResult: {type: 'text'},
    inLedger: {type: 'int'},

    /* ripple-simple fields */
    '"notificationAddress"': {type: 'text', primaryKey: true},
    txType: {type: 'text'},
    txDirection: {type: 'text'},
github ripple / ripple-rest / db / migrations / 20140307230601-client-resource-id_records.js View on Github external
var dbm = require('db-migrate');
var type = dbm.dataType;

exports.up = function(db, callback) {
  db.createTable('client_resource_id_records', {

    /* Auto-generated */
    id: {type: 'int'},
    created_at: {type: 'timestamp'},
    updated_at: {type: 'timestamp'},

    source_account: {type: 'text', primaryKey: true},
    type: {type: 'text', primaryKey: true},
    client_resource_id: {type: 'text', primaryKey: true},
    hash: {type: 'text'},
    ledger: {type: 'text'},
    state: {type: 'text'},
    result: {type: 'text'}
github turt2live / matrix-appservice-instagram-media / src / storage / InstagramStore.js View on Github external
return new Promise((resolve, reject)=> {
            var dbMigrate = DBMigrate.getInstance(true, {
                config: "./config/database.json",
                env: env
            });
            dbMigrate.internals.argv.count = undefined; // HACK: Fix db-migrate from using `config/config.yaml` as the count. See https://github.com/turt2live/matrix-appservice-instagram/issues/11
            dbMigrate.up().then(() => {
                var dbConfigEnv = dbConfig[env];
                if (!dbConfigEnv) throw new Error("Could not find DB config for " + env);

                var opts = {
                    host: dbConfigEnv.host || 'localhost',
                    dialect: 'sqlite',
                    storage: dbConfigEnv.filename,
                    pool: {
                        max: 5,
                        min: 0,
                        idle: 10000
github wzrdtales / node-ultimate-migrate / index.js View on Github external
function executeDump()
{
    if ( argv[ 'cross-compatible' ] || config.getCurrent().settings.compatible )
    {
        console.log( 'Cross Compatible is currently not yet implemented! Switching back to Specific mode.' );
        console.log( 'Note that in compatible mode partitions, fulltext indexes and other DataBase Specific Features you made will be lost. This may be possible in any future release.' );
    }
    else
    {
        console.log( 'Running in DataBase Specific mode.' );
    }

    createMigrationDir( argv[ 'migrations-dir' ], function ( err )
    {
        if ( err )
        {
            log.error( 'Failed to create migration directory at ', argv[ 'migrations-dir' ], err );
            process.exit( 1 );
        }
github wzrdtales / node-ultimate-migrate / index.js View on Github external
if ( action == 'up' )
        {
            executeUp();
        }
        else
        {
            executeDown();
        }
        break;

    case 'db':
        loadConfig();

        if( folder.length < 1 )
        {
            log.info( 'Please enter a valid command, i.e. db:create|db:drop' );
        }
        else
        {
            global.mode = folder[ 1 ];
            executeDB();
        }
        break;

    default:
        log.error( 'Invalid Action: Must be [up|down|create].' );
        optimist.showHelp();
        process.exit( 1 );
        break;
    }
}
github wzrdtales / node-ultimate-migrate / index.js View on Github external
if ( argv.help || argv._.length === 0 )
{
    optimist.showHelp();
    process.exit( 1 );
}

global.migrationTable = argv.table;
global.dbm = dbm;
global.matching = '';
global.mode;
global.verbose = argv.verbose;
global.dryRun = argv[ 'dry-run' ];
if ( global.dryRun )
{
    log.info( 'dry run' );
}

function connect( config, callback )
{
    if ( argv.template !== true )
        config.template = argv.template || config.template;

    template.connect( config, function ( err, tmp )
    {
        if( err )
        {
            callback( err );
            return;
        }

        driver.connect( config, function ( err, db )