@@ -524,7 +524,7 @@ mod tests {
524524 use crate :: db:: datastore:: traits:: IndexDef ;
525525 use crate :: db:: datastore:: traits:: TableDef ;
526526 use crate :: db:: message_log:: MessageLog ;
527- use crate :: db:: relational_db:: ST_TABLES_ID ;
527+ use crate :: db:: relational_db:: { open_db , ST_TABLES_ID } ;
528528
529529 use super :: RelationalDB ;
530530 use crate :: db:: relational_db:: make_default_ostorage;
@@ -840,6 +840,59 @@ mod tests {
840840 Ok ( ( ) )
841841 }
842842
843+ #[ test]
844+ fn test_auto_inc_reload ( ) -> ResultTest < ( ) > {
845+ let ( stdb, tmp_dir) = make_test_db ( ) ?;
846+
847+ let mut tx = stdb. begin_tx ( ) ;
848+ let schema = TableDef {
849+ table_name : "MyTable" . to_string ( ) ,
850+ columns : vec ! [ ColumnDef {
851+ col_name: "my_col" . to_string( ) ,
852+ col_type: AlgebraicType :: I64 ,
853+ is_autoinc: true ,
854+ } ] ,
855+ indexes : vec ! [ ] ,
856+ table_type : StTableType :: User ,
857+ table_access : StAccess :: Public ,
858+ } ;
859+ let table_id = stdb. create_table ( & mut tx, schema) ?;
860+
861+ let sequence = stdb. sequence_id_from_name ( & tx, "MyTable_my_col_seq" ) ?;
862+ assert ! ( sequence. is_some( ) , "Sequence not created" ) ;
863+
864+ stdb. insert ( & mut tx, table_id, product ! [ AlgebraicValue :: I64 ( 0 ) ] ) ?;
865+
866+ let mut rows = stdb
867+ . iter_by_col_range ( & tx, table_id, 0 , AlgebraicValue :: I64 ( 0 ) ..) ?
868+ . map ( |r| * r. view ( ) . elements [ 0 ] . as_i64 ( ) . unwrap ( ) )
869+ . collect :: < Vec < i64 > > ( ) ;
870+ rows. sort ( ) ;
871+
872+ assert_eq ! ( rows, vec![ 1 ] ) ;
873+
874+ stdb. commit_tx ( tx) ?;
875+ drop ( stdb) ;
876+
877+ dbg ! ( "reopen..." ) ;
878+ let stdb = open_db ( & tmp_dir, false ) ?;
879+
880+ let mut tx = stdb. begin_tx ( ) ;
881+
882+ stdb. insert ( & mut tx, table_id, product ! [ AlgebraicValue :: I64 ( 0 ) ] ) ?;
883+
884+ let mut rows = stdb
885+ . iter_by_col_range ( & tx, table_id, 0 , AlgebraicValue :: I64 ( 0 ) ..) ?
886+ . map ( |r| * r. view ( ) . elements [ 0 ] . as_i64 ( ) . unwrap ( ) )
887+ . collect :: < Vec < i64 > > ( ) ;
888+ rows. sort ( ) ;
889+
890+ //TODO: This need the PR that recover the auto_inc, this is for check the db is correctly reopened...
891+ //assert_eq!(rows, vec![1, 2]);
892+ assert_eq ! ( rows, vec![ 1 ] ) ;
893+ Ok ( ( ) )
894+ }
895+
843896 #[ test]
844897 fn test_indexed ( ) -> ResultTest < ( ) > {
845898 let ( stdb, _tmp_dir) = make_test_db ( ) ?;
0 commit comments