rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.19k stars 275 forks source link

Add lock for concurrent migrations running from several nodes #45

Closed dskarataev closed 7 years ago

dskarataev commented 7 years ago

Hi,

could you please add a lock for migrations? Our API runs migrations right before initialization and it's running on more than one node, so we have conflicts because the migrations try to apply at the same time from different nodes. It's ok for CREATE IF NOT EXIST or ALTER but not so good for datafixes like simple INSERT new value.

Please consider to acquire access using GET LOCK or some similar approach, thanks.

http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock

Dynom commented 7 years ago

I'm not sure if @rubenv is considering this, but I personally probably wouldn't merge it in sql-migrate.

I think that the problem you're describing is something you should solve on a different layer in your operations process. Either via the process management or deployment tools you use. Even with locking in place, this isn't non-trivial to add and frankly not part of the problem sql-migrate tries to solve.

sql-migrate is also a library, so it's probably quite doable to hack your own implementation for your specific MySQL use-case.

Just my two cents

rubenv commented 7 years ago

Yup, agreeing with @Dynom here. Let's keep sql-migrate simple.

dselans commented 7 years ago

@dskarataev I had the same exact need and implemented such functionality in #58. I'm not sure if this is the direction that sql-migrate folks want to take it though, so we'll see.