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

Multiple shmig up commands running at the same time #58

Open
shamrin opened this issue Jun 1, 2019 · 1 comment
Open

Multiple shmig up commands running at the same time #58

shamrin opened this issue Jun 1, 2019 · 1 comment

Comments

@shamrin
Copy link
Collaborator

shamrin commented Jun 1, 2019

It seems to me (after reading shmig source code), it's not safe to run multiple shmig up commands at the same time. It could happen in real life if one tries to do shmig up as part of application instance startup. With multiple instances of those running.

This problem is discussed at stackexchange.com, with a potential solution using SELECT FROM ... FOR UPDATE:

  • BEGIN
  • SELECT FROM $SCHEMA_TABLE FOR UPDATE WHERE version=$VERSION
  • if the former statement returns a value, stop
  • apply the migration (ROLLBACK if it fails and stop)
  • INSERT INTO $SCHEMA_TABLE(version) VALUES ($VERSION)
  • COMMIT

@mbucc Would you be open to have this problem fixed in shmig? I could try to contribute the solution.

@mbucc
Copy link
Owner

mbucc commented Jun 4, 2019

Hi,

This would be a valuable fix.

From a quick google, it looks like mysql and postgresql support "select for update"; sqlite3 does not. But I think it is fine to implement for whatever database you are using; I would certainly accept such a pull request.

I would like to add a test to shmig_test to verify bug before fixing it; I'll try and work one up this weekend.

Thanks,

Mark

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

2 participants