---
The logic for migrations is suprisingly simple:
- A new migration will normally create a file with an Up or Down method and a "timestamp" + "description of the purpose of the migration" ( eg. 20191031_080603532_add_tags_to_contacts.cs )
- Every migration, when run on the database will create a new entry in eg. the _migrations table . Some will store the PreviousContext which is a hash of the CurrentScheme before the migrations.
If the application has a live check on startup. It will check the hash of the current db schema, compare it to an entry in the database.
Check if that compares to the latest.
The latest is the latest "migration file with up or down". It will execute all newer once according to the timestamp. Untill the latest one is executed.
A tool also contains a "TargetMigration" for development purpose or for reverting a database back to a previous state.
Every Up or Down migration is run inside a transaction. If it fails, nothing is stored.
There is also a way normally to do a Seed of the database, after the migration is run. But this could be added in the Up or Down method.
PS. All other methods untill now were bad.