What is Entity Frameworks mechanism to prevent mul

2019-07-18 04:14发布

问题:

Of course EF is storing the latest migration to the MigrationHistory table to determine if a specific migration was already executed.

My question is about what EF is doing to prevent multiple executions of the same migration at the same time. Assuming you have two applications which runs under different application domains using the same database. Both apps are starting simultaneously, wherefore both starts to migrate to the latest database migrations. Assume MigrateDatabaseToLatestVersion is set as the initializer.

I think the migration started last fails cause the first executed migration updated the MigrationHistory table just before. Does EF relies here on SQLs transactions to rollback the migration which was too late? Or does it use a smarter mechanism to prevent the execution of the second migration?

回答1:

Although some migration steps one by one run in a separate transaction, the situation is not simple. Not only two (or more) migration step, but migration step and the normal program running can interfere.

Link: It's a bit old, but can useful

update: ideas may be here:

  • Martin Fowler: BlueGreenDeployment
  • Zero Down-time – relational databases
  • Day 3 - Zero-Downtime MySQL Schema Changes