Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmable API not working with MongoDB #474

Open
BorntraegerMarc opened this issue Apr 24, 2017 · 5 comments
Open

Programmable API not working with MongoDB #474

BorntraegerMarc opened this issue Apr 24, 2017 · 5 comments
Assignees
Labels

Comments

@BorntraegerMarc
Copy link
Contributor

BorntraegerMarc commented Apr 24, 2017

Currently db-migrate programmable API doesn't work properly with scope.
As there are two migration scopes (root and test) and so we intent to run down on 'test' scope, down on root scope, up on root scope, then up on test scope in sequence, however, the db-migrate API doesn't work properly as our intention. Once we run down on test scope, the coming up/down would run on the same scope.

To execute up and down in sequence with different scopes, DBMigrateHelper was added as a mediator and now we can mix up and down at our convenience (but we should invoke resetInstance method between up and down):

                let dbm = DBMigrateHelper.getInstance();
                DBMigrateHelper.executeDown(dbm, 'test')
                    .then(() => DBMigrateHelper.executeDown(dbm))
                    .then(() => DBMigrateHelper.resetInstanceAsync(dbm))
                    .then(() => DBMigrateHelper.executeUp(dbm))
                    .then(() => DBMigrateHelper.executeUp(dbm, 'test'))
                    .then(() => resolve());

DBMigrateHelper:

class DBMigrateHelper {
    public static getInstance() {
        return DBMigrate.getInstance(true);
    }

    public static resetInstance(dbm: any): void {
        if (dbm.internals.matching) {
            delete dbm.internals.matching;
        }
        if (dbm.internals.migrationMode) {
            delete dbm.internals.migrationMode;
        }
        if (dbm.internals.argv.count) {
            delete dbm.internals.argv.count;
        }
        if (dbm.internals.locTitle) {
            delete dbm.internals.locTitle;
        }
        if (dbm.internals.migrationsDir) {
            delete dbm.internals.migrationsDir;
        }
    }

    public static resetInstanceAsync(dbm: any): Promise<any> {
        return new Promise((resolve, reject) => {
            try {
                DBMigrateHelper.resetInstance(dbm);
                resolve();
            } catch (e) {
                reject(e);
            }
        });
    }

    public static executeUp(dbm: any, scope?: string): any {
        return dbm.up(100, !scope ? '' : scope);
    }

    public static executeDown(dbm: any, scope?: string): any {
        return dbm.down(100, !scope ? '' : scope);
    }
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@BorntraegerMarc
Copy link
Contributor Author

No update @wzrdtales ?

@wzrdtales
Copy link
Member

Sry for being that late @BorntraegerMarc

I can't really get what your problem is from what you've written.

Once we run down on test scope, the coming up/down would run on the same scope.

Where exactly is the problem there? As expected if you run in the same scope up after down it will rexecute from the point you have migrated there. Can you give a reproducable example so I can have a closer look?

@BorntraegerMarc
Copy link
Contributor Author

@wzrdtales No problem :)
Basically while working with programmable API

  • it doesn't work with/across multiple scopes at the same time:
                dbmigrate.reset()
                     .then(() => dbmigrate.down(null, null, 'all'))
                     .then(() => dbmigrate.down())
                     .then(() => dbmigrate.up())
                     .then(() => dbmigrate.up(null, null, 'all'))
                     .then(() => resolve());

And basically we had the scope base and test, which did not get loaded correctly.
-> due to incomplete cross-scope support;

The problem can only be fixed by resetting migrate instance manually (introducing the already posted DBMigrateHelper class).

So maybe I'm completely missing how to use the library?

@BorntraegerMarc
Copy link
Contributor Author

any update on this @wzrdtales ? :)

@wzrdtales
Copy link
Member

sry, have been out of time again...

I understand now where you're encountering problems, gonna have a look at this.

@wzrdtales wzrdtales self-assigned this Jun 25, 2017
@wzrdtales wzrdtales added the bug label Jun 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants