@@ -14,14 +14,10 @@ use std::path::{Path, PathBuf};
1414/// lexicographically by filename. Each file becomes one `MigrationUnit`.
1515///
1616/// Down migrations are detected by filename patterns: `.down.sql` or `_down.sql`.
17+ #[ derive( Default ) ]
1718pub struct SqlLoader ;
1819
1920impl SqlLoader {
20- /// Create a new `SqlLoader`.
21- pub fn new ( ) -> Self {
22- Self
23- }
24-
2521 /// Load a single SQL file and parse it into a `MigrationUnit`.
2622 ///
2723 /// The file is read entirely into memory, parsed into IR nodes, and
@@ -52,12 +48,6 @@ impl SqlLoader {
5248 }
5349}
5450
55- impl Default for SqlLoader {
56- fn default ( ) -> Self {
57- Self :: new ( )
58- }
59- }
60-
6151impl MigrationLoader for SqlLoader {
6252 /// Load migrations from the given paths.
6353 ///
@@ -108,8 +98,6 @@ impl MigrationLoader for SqlLoader {
10898}
10999
110100/// Collect all `.sql` files from a directory (non-recursive).
111- ///
112- /// Returns the files sorted lexicographically by filename.
113101fn collect_sql_files ( dir : & Path ) -> Result < Vec < PathBuf > , LoadError > {
114102 let entries = std:: fs:: read_dir ( dir) . map_err ( |e| LoadError :: Io {
115103 path : dir. to_path_buf ( ) ,
@@ -130,7 +118,6 @@ fn collect_sql_files(dir: &Path) -> Result<Vec<PathBuf>, LoadError> {
130118 }
131119 }
132120
133- files. sort ( ) ;
134121 Ok ( files)
135122}
136123
@@ -255,7 +242,7 @@ mod tests {
255242 // Also create a non-SQL file that should be ignored
256243 fs:: write ( dir. path ( ) . join ( "README.md" ) , "# Migrations" ) . expect ( "write" ) ;
257244
258- let loader = SqlLoader :: new ( ) ;
245+ let loader = SqlLoader ;
259246 let history = loader
260247 . load ( & [ dir. path ( ) . to_path_buf ( ) ] )
261248 . expect ( "Failed to load migrations" ) ;
@@ -274,21 +261,21 @@ mod tests {
274261 let file_path = dir. path ( ) . join ( "migration.sql" ) ;
275262 fs:: write ( & file_path, "CREATE TABLE t (id int);" ) . expect ( "write" ) ;
276263
277- let loader = SqlLoader :: new ( ) ;
264+ let loader = SqlLoader ;
278265 let history = loader. load ( & [ file_path] ) . expect ( "Failed to load migration" ) ;
279266 assert_eq ! ( history. units. len( ) , 1 ) ;
280267 }
281268
282269 #[ test]
283270 fn test_loader_nonexistent_path ( ) {
284- let loader = SqlLoader :: new ( ) ;
271+ let loader = SqlLoader ;
285272 let result = loader. load ( & [ PathBuf :: from ( "/nonexistent/path" ) ] ) ;
286273 assert ! ( result. is_err( ) ) ;
287274 }
288275
289276 #[ test]
290277 fn test_loader_empty_paths ( ) {
291- let loader = SqlLoader :: new ( ) ;
278+ let loader = SqlLoader ;
292279 let history = loader. load ( & [ ] ) . expect ( "Empty paths should succeed" ) ;
293280 assert ! ( history. units. is_empty( ) ) ;
294281 }
@@ -309,7 +296,7 @@ mod tests {
309296 )
310297 . expect ( "write" ) ;
311298
312- let loader = SqlLoader :: new ( ) ;
299+ let loader = SqlLoader ;
313300 let history = loader
314301 . load ( & [ dir1. path ( ) . to_path_buf ( ) , dir2. path ( ) . to_path_buf ( ) ] )
315302 . expect ( "Failed to load migrations" ) ;
0 commit comments