@@ -427,7 +427,10 @@ fn auto_migrate_table<'def>(plan: &mut AutoMigratePlan<'def>, old: &'def TableDe
427
427
428
428
// Note that the diff algorithm relies on `ModuleDefLookup` for `ColumnDef`,
429
429
// which looks up columns by NAME, NOT position: precisely to allow this step to work!
430
- // We reject changes to
430
+
431
+ // Note: We reject changes to positions. This means that, if a column was present in the old version of the table,
432
+ // it must be in the same place in the new version of the table.
433
+ // This guarantees that any added columns live at the end of the table.
431
434
let positions_ok = if old. col_id == new. col_id {
432
435
Ok ( ( ) )
433
436
} else {
@@ -439,6 +442,7 @@ fn auto_migrate_table<'def>(plan: &mut AutoMigratePlan<'def>, old: &'def TableDe
439
442
440
443
( types_ok, positions_ok)
441
444
. combine_errors ( )
445
+ // row_type_changed, column_added
442
446
. map ( |( x, _) | ProductMonoid ( x, Any ( false ) ) )
443
447
}
444
448
}
@@ -871,7 +875,7 @@ mod tests {
871
875
)
872
876
// add column sequence
873
877
. with_column_sequence ( 0 )
874
- . with_default_column_value ( 3 , AlgebraicValue :: U32 ( 5 ) )
878
+ . with_default_column_value ( 3 , AlgebraicValue :: U32 ( 5 ) ) // we need a new
875
879
// change access
876
880
. with_access ( TableAccess :: Private )
877
881
. finish ( ) ;
@@ -1123,7 +1127,7 @@ mod tests {
1123
1127
( "sum1" , new_sum1_refty. into ( ) ) ,
1124
1128
( "prod1" , new_prod1_refty. into ( ) ) ,
1125
1129
// remove count
1126
- ( "weight" , AlgebraicType :: U16 ) , // add weight
1130
+ ( "weight" , AlgebraicType :: U16 ) , // add weight; we don't set a default, which makes this an error.
1127
1131
] ) ,
1128
1132
true ,
1129
1133
)
@@ -1164,6 +1168,7 @@ mod tests {
1164
1168
1165
1169
expect_error_matching ! (
1166
1170
result,
1171
+ // This is an error because we didn't set a default value.
1167
1172
AutoMigrateError :: AddColumn {
1168
1173
table,
1169
1174
column
0 commit comments