Multiple `shmig up` commands running at the same time
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:
BEGINSELECT FROM $SCHEMA_TABLE FOR UPDATE WHERE version=$VERSION- if the former statement returns a value, stop
- apply the migration (
ROLLBACKif 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.
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