db-migrator-core

1.0.0-alpha.0 • Public • Published

db-migrator-core

A database migrator tool built in node.js. This package can only work with one of the sub-packages provided below:

  • db-migrator-mongo

Usage

const { DbMigrator } = require('db-migrator-core');
const DbMigratorMongo = require('db-migrator-mongo');

const migrator = new DbMigrator();
migrator.loadModule(DbMigratorMongo); // load any sub-package

// migration configs
const migrators = [
    {
        from: { collection: 'students' },
        to: { collection: 'students_copy' },
    },
    {
        from: { collection: 'techers' },
        to: { collection: 'techers_copy' },
    },
];

(async () => {

    try {

        // Prepare migrators
        const migrator = new DbMigrator();
        migrator.loadModule(DbMigratorMongo);

        // Connect source and target databases
        await migrator.connectSourceDatabase('mongo', sourceConfig);
        await migrator.connectTargetDatabase('mongo', targetConfig);

        // Validate migrators
        const errors = migrator.validateMigrators(migrators);
        if (errors.length) return console.error(errors);

        // Do Migration
        migrator.setMigrators(migrators);
        await migrator.migrate();        

        console.log('Migration Succeeded !')

    } catch(err) {
        console.error(err);
    }

})();

Package Sidebar

Install

npm i db-migrator-core

Weekly Downloads

1

Version

1.0.0-alpha.0

License

MIT

Unpacked Size

22.5 kB

Total Files

12

Last publish

Collaborators

  • abhishekbadoni