mongo-migrate-manager

1.1.1 • Public • Published

mongo-migrate-manager

MongoDB migrations manager for nodeJs.

How to install

npm i mongo-migrate-manager

Getting Started

To create a new migration:

  1. first, you need to create a new class extending the BaseMigration class from mongo-migrate-manager package.
  2. second, add the new migration to migrationTypes (just for cleaner code). However, you can add it in the same file with the migrations manager.
  3. import and run the migration manager.

Example Usage

migrate_test_one.ts

const migrationsModule = require('mongo-migrate-manager');


export default class MigrationTestOne extends migrationsModule.BaseMigration {
    
    private static instance: MigrationTestOne;


    private constructor() {
        super("migrate_test_one");
    }
    

    public static getInstance() {

        if(!this.instance) {
            this.instance = new MigrationTestOne();
        }
        
        return this.instance; 
    }


    public async perform(): Promise<void> {
        console.log("performing migrate_test_one");
    }


    public async test(): Promise<void> {
        console.log("testing migrate_test_one");
    }
}

migrationTypes.ts

import migrate_test_one from './migrate_test_one';


const migrationTypes: any = [
    migrate_test_one,
];

export default migrationTypes;

migrationManager.ts

import migrationTypes from "./migrationTypes";
const migrationsModule = require('mongo-migrate-manager');


const migrationManager = new migrationsModule.MigrationScript(migrationTypes, "mongodb://localhost:27017/migrations-test");

/*
* init: only updates the migration to Database, but doesnot perform the migration
*/
migrationManager.init();

/*
* run: Check if migration is in Database. If not it adds and runs it.
*/
migrationManager.run();

Package Sidebar

Install

npm i mongo-migrate-manager

Weekly Downloads

34

Version

1.1.1

License

ISC

Unpacked Size

27.5 kB

Total Files

25

Last publish

Collaborators

  • m4gdy