But it looks more like this. The database state is modified not only by migrations but by application as well. = database state , = database state after one or more application delta Δ = migration delta (written by programmer) Δ, = application delta (caused by application itself)
Δ1, implies set of safe operations in Δ1 e.g. allowing only DML (insert, update…) in Δ1, makes DDL (alter, drop…) in Δ1 safe UNKNOWN PARTIALLY KNOWN STATE Δ1,0 Q1 Q2* Q1,1 Q1,n … Q1,2 Δ1 Δ1,1 Δ1,2 KNOWN STATE
all of Δ1 to Δ−1 and none other Δ must have been safely executed ∀: Δ must contain only operations safe regarding to our knowledge of , ∗ which depends on restriction placed on Δ, , ∗ Δ +1 ∗
into 2 safe when inserting into 1 when ID range is split into disjoint subsets (for app and for migrations) inserting without ID makes UPDATE impossible should be avoided
the end you must always „rebase“ your migrations once executed migration cannot be changed previous migration must have not failed programmer must fix failed migration manually This ensures that migration starts every time from (at least partially) known state.