@@ -83,6 +83,10 @@ pub struct VespertideConfig {
8383 /// SeaORM-specific export configuration.
8484 #[ serde( default ) ]
8585 pub seaorm : SeaOrmConfig ,
86+ /// Prefix to add to all table names (including migration version table).
87+ /// Default: "" (no prefix)
88+ #[ serde( default ) ]
89+ pub prefix : String ,
8690}
8791
8892fn default_model_export_dir ( ) -> PathBuf {
@@ -101,6 +105,7 @@ impl Default for VespertideConfig {
101105 migration_filename_pattern : default_migration_filename_pattern ( ) ,
102106 model_export_dir : default_model_export_dir ( ) ,
103107 seaorm : SeaOrmConfig :: default ( ) ,
108+ prefix : String :: new ( ) ,
104109 }
105110 }
106111}
@@ -150,6 +155,20 @@ impl VespertideConfig {
150155 pub fn seaorm ( & self ) -> & SeaOrmConfig {
151156 & self . seaorm
152157 }
158+
159+ /// Prefix to add to all table names.
160+ pub fn prefix ( & self ) -> & str {
161+ & self . prefix
162+ }
163+
164+ /// Apply prefix to a table name.
165+ pub fn apply_prefix ( & self , table_name : & str ) -> String {
166+ if self . prefix . is_empty ( ) {
167+ table_name. to_string ( )
168+ } else {
169+ format ! ( "{}{}" , self . prefix, table_name)
170+ }
171+ }
153172}
154173
155174#[ cfg( test) ]
@@ -173,5 +192,26 @@ mod tests {
173192 vec![ "vespera::Schema" . to_string( ) ]
174193 ) ;
175194 assert ! ( config. seaorm. extra_model_derives. is_empty( ) ) ;
195+ assert_eq ! ( config. prefix, "" ) ;
196+ }
197+
198+ #[ test]
199+ fn test_vespertide_config_prefix ( ) {
200+ let config = VespertideConfig {
201+ prefix : "myapp_" . to_string ( ) ,
202+ ..Default :: default ( )
203+ } ;
204+
205+ assert_eq ! ( config. prefix( ) , "myapp_" ) ;
206+ assert_eq ! ( config. apply_prefix( "users" ) , "myapp_users" ) ;
207+ assert_eq ! ( config. apply_prefix( "posts" ) , "myapp_posts" ) ;
208+ }
209+
210+ #[ test]
211+ fn test_vespertide_config_empty_prefix ( ) {
212+ let config = VespertideConfig :: default ( ) ;
213+
214+ assert_eq ! ( config. prefix( ) , "" ) ;
215+ assert_eq ! ( config. apply_prefix( "users" ) , "users" ) ;
176216 }
177217}
0 commit comments