@@ -656,6 +656,44 @@ test "migration creation bounds repeated version collisions" {
656656 try std .testing .expectEqual (max_migration_create_attempts , collisions .attempts );
657657}
658658
659+ test "migration creation preserves versions wider than the minimum padding" {
660+ var tmp = std .testing .tmpDir (.{});
661+ defer tmp .cleanup ();
662+ try tmp .dir .createDirPath (std .testing .io , "migrations" );
663+ try tmp .dir .writeFile (std .testing .io , .{
664+ .sub_path = "migrations/V9999__previous.sql" ,
665+ .data = migration_template ,
666+ });
667+
668+ const path = try createNextMigrationFile (
669+ std .testing .allocator ,
670+ tmp .dir ,
671+ std .testing .io ,
672+ "migrations" ,
673+ "wide_version" ,
674+ );
675+ defer std .testing .allocator .free (path );
676+ try std .testing .expectEqualStrings ("migrations/V10000__wide_version.sql" , path );
677+
678+ const id = try zsql .migrate .parseFilename (path );
679+ try std .testing .expectEqual (@as (u64 , 10_000 ), id .version );
680+ }
681+
682+ test "migration version discovery rejects u64 exhaustion" {
683+ var tmp = std .testing .tmpDir (.{});
684+ defer tmp .cleanup ();
685+ try tmp .dir .createDirPath (std .testing .io , "migrations" );
686+ try tmp .dir .writeFile (std .testing .io , .{
687+ .sub_path = "migrations/V18446744073709551615__last.sql" ,
688+ .data = migration_template ,
689+ });
690+
691+ try std .testing .expectError (
692+ error .MigrationVersionConflict ,
693+ nextMigrationVersion (tmp .dir , std .testing .io , "migrations" ),
694+ );
695+ }
696+
659697fn nextMigrationVersion (root : std.Io.Dir , io : std.Io , dir_path : []const u8 ) ! u64 {
660698 var dir = root .openDir (io , dir_path , .{ .iterate = true }) catch return 1 ;
661699 defer dir .close (io );
0 commit comments