@@ -184,6 +184,26 @@ impl DatabaseConnectionPlugin for PostgreSqlPlugin {
184184 result. get_mut_errors ( ) . push ( error. to_string ( ) ) ;
185185 }
186186 }
187+ if let Err ( error) = auto_creator. create_indexes ( ) . await {
188+ AutoCreationLogger :: log_auto_creation_error (
189+ & error,
190+ "Index creation" ,
191+ PluginType :: PostgreSQL ,
192+ Some ( instance. get_database ( ) . as_str ( ) ) ,
193+ )
194+ . await ;
195+ result. get_mut_errors ( ) . push ( error. to_string ( ) ) ;
196+ }
197+ if let Err ( error) = auto_creator. init_data ( ) . await {
198+ AutoCreationLogger :: log_auto_creation_error (
199+ & error,
200+ "Init data" ,
201+ PluginType :: PostgreSQL ,
202+ Some ( instance. get_database ( ) . as_str ( ) ) ,
203+ )
204+ . await ;
205+ result. get_mut_errors ( ) . push ( error. to_string ( ) ) ;
206+ }
187207 if let Err ( error) = auto_creator. verify_connection ( ) . await {
188208 AutoCreationLogger :: log_auto_creation_error (
189209 & error,
@@ -415,6 +435,36 @@ impl PostgreSqlAutoCreation {
415435 fn get_database_schema ( & self ) -> & DatabaseSchema {
416436 & self . schema
417437 }
438+
439+ #[ instrument_trace]
440+ async fn create_indexes ( & self ) -> Result < ( ) , AutoCreationError > {
441+ let connection: DatabaseConnection = self . create_target_connection ( ) . await ?;
442+ let schema: & DatabaseSchema = self . get_database_schema ( ) ;
443+ for index_sql in schema. get_indexes ( ) {
444+ if let Err ( error) = self . execute_sql ( & connection, index_sql) . await {
445+ AutoCreationLogger :: log_auto_creation_error (
446+ & error,
447+ "Index creation" ,
448+ PluginType :: PostgreSQL ,
449+ Some ( self . instance . get_database ( ) . as_str ( ) ) ,
450+ )
451+ . await ;
452+ }
453+ }
454+ for constraint_sql in schema. get_constraints ( ) {
455+ if let Err ( error) = self . execute_sql ( & connection, constraint_sql) . await {
456+ AutoCreationLogger :: log_auto_creation_error (
457+ & error,
458+ "Constraint creation" ,
459+ PluginType :: PostgreSQL ,
460+ Some ( self . instance . get_database ( ) . as_str ( ) ) ,
461+ )
462+ . await ;
463+ }
464+ }
465+ let _: Result < ( ) , DbErr > = connection. close ( ) . await ;
466+ Ok ( ( ) )
467+ }
418468}
419469
420470impl DatabaseAutoCreation for PostgreSqlAutoCreation {
@@ -468,36 +518,33 @@ impl DatabaseAutoCreation for PostgreSqlAutoCreation {
468518 . await ;
469519 }
470520 }
471- for index_sql in schema. get_indexes ( ) {
472- if let Err ( error) = self . execute_sql ( & connection, index_sql) . await {
473- AutoCreationLogger :: log_auto_creation_error (
474- & error,
475- "Index creation" ,
476- PluginType :: PostgreSQL ,
477- Some ( self . instance . get_database ( ) . as_str ( ) ) ,
478- )
479- . await ;
480- }
481- }
482- for constraint_sql in schema. get_constraints ( ) {
483- if let Err ( error) = self . execute_sql ( & connection, constraint_sql) . await {
521+ let _: Result < ( ) , DbErr > = connection. close ( ) . await ;
522+ AutoCreationLogger :: log_tables_created (
523+ & created_tables,
524+ self . instance . get_database ( ) . as_str ( ) ,
525+ PluginType :: PostgreSQL ,
526+ )
527+ . await ;
528+ Ok ( created_tables)
529+ }
530+
531+ #[ instrument_trace]
532+ async fn init_data ( & self ) -> Result < ( ) , AutoCreationError > {
533+ let connection: DatabaseConnection = self . create_target_connection ( ) . await ?;
534+ let schema: & DatabaseSchema = self . get_database_schema ( ) ;
535+ for init_data_sql in schema. get_init_data ( ) {
536+ if let Err ( error) = self . execute_sql ( & connection, init_data_sql) . await {
484537 AutoCreationLogger :: log_auto_creation_error (
485538 & error,
486- "Constraint creation " ,
539+ "Init data insertion " ,
487540 PluginType :: PostgreSQL ,
488541 Some ( self . instance . get_database ( ) . as_str ( ) ) ,
489542 )
490543 . await ;
491544 }
492545 }
493546 let _: Result < ( ) , DbErr > = connection. close ( ) . await ;
494- AutoCreationLogger :: log_tables_created (
495- & created_tables,
496- self . instance . get_database ( ) . as_str ( ) ,
497- PluginType :: PostgreSQL ,
498- )
499- . await ;
500- Ok ( created_tables)
547+ Ok ( ( ) )
501548 }
502549
503550 #[ instrument_trace]
0 commit comments