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

Database not unlocked when External DB Client is used #885

Open
seanadkinson opened this issue Mar 16, 2022 · 2 comments
Open

Database not unlocked when External DB Client is used #885

seanadkinson opened this issue Mar 16, 2022 · 2 comments

Comments

@seanadkinson
Copy link

Hi there,

I am running pgMigrate programmatically on app startup via something similar to the following:

   await pgMigrate({
        dbClient: dbClient,
        migrationsTable: 'migrations',
        dir: path.join(__dirname, '..', '..', 'migrations'),
        direction: 'up',
    });

You can see I am providing an external dbClient.

When running my app with multiple nodes, the first node successfully runs the migrations, but every subsequent node gets "Error: Another migration is already running"

I believe this is happening because when you check that the database is connected before unlocking here, it is always false, since you don't set the connectionStatus for external clients here. This means that the database remains locked forever.

I think if you set connectionStatus = ConnectionStatus.CONNECTED for external clients, this should solve the issue. Thoughts?

@AHBruns
Copy link

AHBruns commented May 9, 2022

I'm running into this as well.

@matei-radu
Copy link

matei-radu commented May 26, 2022

I'm having this issue with the same setup: running the migration function programmatically and with an external dbClient. Although my scenario is a bit different, as I first encountered the problem running tests (thus running pgMigrate more than once because of some test cases).

I think @seanadkinson explanation on the connection status when using an external client makes sense: with the current setup, the status will remain ConnectionStatus.DISCONNECTED when using an external client, then unlock is never called.

I tried running pgMigrate with the option noLock: true and indeed I no longer get the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants