How to use the db-migrate.getInstance function in db-migrate

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 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 Unleash / unleash / migrator.js View on Github external
function migrateDb({ databaseUrl, databaseSchema = 'public' }) {
    const custom = parseDbUrl(databaseUrl);
    custom.schema = databaseSchema;
    const dbmigrate = getInstance(true, {
        cwd: __dirname,
        config: { custom },
        env: 'custom',
    });
    return dbmigrate.up();
}
github mozilla / voice-web / server / src / lib / model / db / schema.ts View on Github external
async upgrade() {
    const {
      MYSQLDBNAME,
      MYSQLHOST,
      DB_ROOT_PASS,
      DB_ROOT_USER,
      VERSION,
    } = this.config;
    const dbMigrate = DBMigrate.getInstance(true, {
      config: {
        dev: {
          driver: 'mysql',
          database: MYSQLDBNAME,
          host: MYSQLHOST,
          password: DB_ROOT_PASS,
          user: DB_ROOT_USER,
          multipleStatements: true,
        },
      },
      cwd: path.isAbsolute(__dirname)
        ? __dirname
        : path.resolve(path.join('server', __dirname)),
    });
    await (VERSION ? dbMigrate.sync(VERSION) : dbMigrate.up());
  }
github turt2live / matrix-dimension / src / storage / DimensionStore.js View on Github external
return new Promise((resolve, reject)=> {
            var dbMigrate = DBMigrate.getInstance(true, {
                config: "./config/database.json",
                env: env
            });
            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',
                    pool: {
                        max: 5,
                        min: 0,
                        idle: 10000
                    },
                    storage: dbConfigEnv.filename,
github tundra-code / aurora / src / renderer / lib / io / sqlite / setup.js View on Github external
ensureDirExists();
const DBMigrate = require("db-migrate");
const dbfile = dbFilePath(process.env.NODE_ENV);
const knex = require("knex")({
  client: "sqlite3",
  connection: {
    filename: dbfile
  },
  useNullAsDefault: true
});
const bookshelf = require("bookshelf")(knex);
const cascadeDelete = require("bookshelf-cascade-delete");
bookshelf.plugin(cascadeDelete);

//getting an instance of dbmigrate
const dbmigrate = DBMigrate.getInstance(true, {
  env: process.env.NODE_ENV,
  config: configFilePath(),
  throwUncatched: true
});

function loadDB() {
  if (global.DB_IS_UP) {
    return new Promise(res => res());
  }

  global.DB_IS_UP = true;
  dbmigrate.silence(true);
  return dbmigrate.up();
}

export { bookshelf, loadDB, createDatabaseConfig, ensureDirExists };
github gpimblott / TechRadar / database / runMigrations.js View on Github external
/**
 * Migration runner, which loads process.env vars via dotenv before running the migrations
 */
require('dotenv').config({path: 'process.env', silent: false});
var DBMigrate = require('db-migrate');

var migrateInstance = DBMigrate.getInstance();
migrateInstance.run();
github machinomy / machinomy / packages / machinomy / src / storage / SqlMigrator.ts View on Github external
protected constructor (log: Logger, config: DBMigrate.InstanceOptions) {
    this.log = log
    log.debug('migrator config %o', config)
    this.migrationsPath = (config.cmdOptions as Indexed)['migrations-dir']
    this.dbmigrate = DBMigrate.getInstance(true, config)
  }