@@ -13,34 +13,41 @@ pub(super) fn init_duckdb(
1313 duckdb_config : Option < DuckdbConfig > ,
1414 mut migrations_runner : Runner ,
1515) -> Result < r2d2:: Pool < DuckdbConnectionManager > > {
16- let conn = DuckdbConnectionManager :: file ( path) ?;
17- let pool = r2d2:: Pool :: new ( conn) ?;
18- migrations_runner. set_migration_table_name ( "migrations" ) ;
16+ let mut flags =
17+ duckdb:: Config :: default ( ) . access_mode ( duckdb:: AccessMode :: ReadWrite ) ?. with ( "enable_fsst_vectors" , "true" ) ?;
1918
20- for migration in migrations_runner. run_iter ( & mut DuckDBConnection ( pool. get ( ) ?) ) {
21- match migration {
22- Ok ( migration) => {
23- tracing:: info!( "Applied migration: {}" , migration) ;
24- }
25- Err ( err) => {
26- bail ! ( "Failed to apply migration: {}" , err) ;
27- }
19+ if let Some ( duckdb_config) = duckdb_config {
20+ if let Some ( memory_limit) = duckdb_config. memory_limit {
21+ flags = flags. max_memory ( & memory_limit) ?;
22+ }
23+
24+ if let Some ( threads) = duckdb_config. threads {
25+ flags = flags. threads ( ( u16:: try_from ( threads) ?) . try_into ( ) ?) ?;
2826 }
2927 }
3028
29+ let conn = DuckdbConnectionManager :: file_with_flags ( path, flags) ?;
30+ let pool = r2d2:: Pool :: new ( conn) ?;
31+
3132 {
3233 let conn = pool. get ( ) ?;
34+ conn. execute ( "PRAGMA enable_checkpoint_on_shutdown; LOAD core_functions;" , [ ] ) ?;
3335 conn. pragma_update ( None , "allow_community_extensions" , & "false" ) ?;
34- conn. pragma_update ( None , "enable_external_access" , & "false" ) ?;
35- conn. pragma_update ( None , "enable_fsst_vectors" , & "true" ) ?;
36-
37- if let Some ( duckdb_config) = duckdb_config {
38- if let Some ( memory_limit) = duckdb_config. memory_limit {
39- conn. pragma_update ( None , "memory_limit" , & memory_limit) ?;
40- }
36+ conn. pragma_update ( None , "autoinstall_known_extensions" , & "false" ) ?;
37+ conn. pragma_update ( None , "autoload_known_extensions" , & "false" ) ?;
38+ }
4139
42- if let Some ( threads) = duckdb_config. threads {
43- conn. pragma_update ( None , "threads" , & threads. to_string ( ) ) ?;
40+ {
41+ let conn = pool. get ( ) ?;
42+ migrations_runner. set_migration_table_name ( "migrations" ) ;
43+ for migration in migrations_runner. run_iter ( & mut DuckDBConnection ( conn) ) {
44+ match migration {
45+ Ok ( migration) => {
46+ tracing:: info!( "Applied migration: {}" , migration) ;
47+ }
48+ Err ( err) => {
49+ bail ! ( "Failed to apply migration: {}" , err) ;
50+ }
4451 }
4552 }
4653 }
0 commit comments