@@ -427,7 +427,10 @@ fn auto_migrate_table<'def>(plan: &mut AutoMigratePlan<'def>, old: &'def TableDe
427427
428428 // Note that the diff algorithm relies on `ModuleDefLookup` for `ColumnDef`,
429429 // 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.
431434 let positions_ok = if old. col_id == new. col_id {
432435 Ok ( ( ) )
433436 } else {
@@ -439,6 +442,7 @@ fn auto_migrate_table<'def>(plan: &mut AutoMigratePlan<'def>, old: &'def TableDe
439442
440443 ( types_ok, positions_ok)
441444 . combine_errors ( )
445+ // row_type_changed, column_added
442446 . map ( |( x, _) | ProductMonoid ( x, Any ( false ) ) )
443447 }
444448 }
@@ -871,7 +875,7 @@ mod tests {
871875 )
872876 // add column sequence
873877 . 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
875879 // change access
876880 . with_access ( TableAccess :: Private )
877881 . finish ( ) ;
@@ -1123,7 +1127,7 @@ mod tests {
11231127 ( "sum1" , new_sum1_refty. into ( ) ) ,
11241128 ( "prod1" , new_prod1_refty. into ( ) ) ,
11251129 // 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.
11271131 ] ) ,
11281132 true ,
11291133 )
@@ -1164,6 +1168,7 @@ mod tests {
11641168
11651169 expect_error_matching ! (
11661170 result,
1171+ // This is an error because we didn't set a default value.
11671172 AutoMigrateError :: AddColumn {
11681173 table,
11691174 column
0 commit comments