@@ -1038,6 +1038,7 @@ fn metadata_from_row(row: RowRef<'_>) -> Result<Metadata> {
1038
1038
#[ cfg( test) ]
1039
1039
mod tests {
1040
1040
use super :: * ;
1041
+ use crate :: db:: datastore:: locking_tx_datastore:: tx_state:: PendingSchemaChange ;
1041
1042
use crate :: db:: datastore:: system_tables:: {
1042
1043
system_tables, StColumnRow , StConstraintData , StConstraintFields , StConstraintRow , StIndexAlgorithm ,
1043
1044
StIndexFields , StIndexRow , StRowLevelSecurityFields , StScheduledFields , StSequenceFields , StSequenceRow ,
@@ -2902,11 +2903,25 @@ mod tests {
2902
2903
2903
2904
// Create a transaction and drop the table and roll back.
2904
2905
let mut tx = begin_mut_tx ( & datastore) ;
2906
+ assert_eq ! ( & * tx. tx_state. pending_schema_changes, [ ] ) ;
2905
2907
assert ! ( datastore. drop_table_mut_tx( & mut tx, table_id) . is_ok( ) ) ;
2908
+ assert_matches ! (
2909
+ & * tx. tx_state. pending_schema_changes,
2910
+ [
2911
+ PendingSchemaChange :: IndexRemoved ( ..) ,
2912
+ PendingSchemaChange :: IndexRemoved ( ..) ,
2913
+ PendingSchemaChange :: SequenceRemoved ( ..) ,
2914
+ PendingSchemaChange :: ConstraintRemoved ( ..) ,
2915
+ PendingSchemaChange :: ConstraintRemoved ( ..) ,
2916
+ PendingSchemaChange :: TableRemoved ( removed_table_id, _)
2917
+ ]
2918
+ if * removed_table_id == table_id
2919
+ ) ;
2906
2920
datastore. rollback_mut_tx ( tx) ;
2907
2921
2908
2922
// Ensure the table still exists in the next transaction.
2909
2923
let tx = begin_mut_tx ( & datastore) ;
2924
+ assert_eq ! ( & * tx. tx_state. pending_schema_changes, [ ] ) ;
2910
2925
assert ! (
2911
2926
datastore. table_id_exists_mut_tx( & tx, & table_id) ,
2912
2927
"Table should still exist" ,
@@ -2919,10 +2934,23 @@ mod tests {
2919
2934
fn test_create_table_is_transactional ( ) -> ResultTest < ( ) > {
2920
2935
// Create a table in a failed transaction.
2921
2936
let ( datastore, tx, table_id) = setup_table ( ) ?;
2937
+ assert_matches ! (
2938
+ & * tx. tx_state. pending_schema_changes,
2939
+ [
2940
+ PendingSchemaChange :: TableAdded ( added_table_id) ,
2941
+ PendingSchemaChange :: IndexAdded ( ..) ,
2942
+ PendingSchemaChange :: IndexAdded ( ..) ,
2943
+ PendingSchemaChange :: ConstraintAdded ( ..) ,
2944
+ PendingSchemaChange :: ConstraintAdded ( ..) ,
2945
+ PendingSchemaChange :: SequenceAdded ( ..) ,
2946
+ ]
2947
+ if * added_table_id == table_id
2948
+ ) ;
2922
2949
datastore. rollback_mut_tx ( tx) ;
2923
2950
2924
2951
// Nothing should have happened.
2925
2952
let tx = begin_mut_tx ( & datastore) ;
2953
+ assert_eq ! ( & * tx. tx_state. pending_schema_changes, [ ] ) ;
2926
2954
assert ! (
2927
2955
!datastore. table_id_exists_mut_tx( & tx, & table_id) ,
2928
2956
"Table should not exist"
0 commit comments