@@ -28,12 +28,10 @@ public actor Driver {
2828 enum Usage {
2929 case migration
3030 case queries
31- case alwaysMigration
3231 }
3332
3433 enum Error : Swift . Error {
3534 case invalidMigrationName( String )
36- case canOnlyHaveOneAlwaysMigration
3735 }
3836
3937 init ( fileSystem: FileSystem ) {
@@ -52,21 +50,16 @@ public actor Driver {
5250 let migrationsPath = migrationsPath ( at: path)
5351 let queriesPath = queriesPath ( at: path)
5452
55- let ( migrationFiles, alwaysMigration) = try organizeMigrations (
56- fileNames: fileSystem. files ( atPath: migrationsPath)
57- )
53+ let migrationFiles = try fileSystem. files ( atPath: migrationsPath)
5854 let queriesFiles = try fileSystem. files ( atPath: queriesPath)
5955
56+ try validateMigrations ( fileNames: migrationFiles)
57+
6058 // Migrations must be run synchronously in order.
6159 for migration in migrationFiles {
6260 try compile ( file: migration, in: migrationsPath, usage: . migration)
6361 }
6462
65- // Always migrations always run after
66- if let alwaysMigration {
67- try compile ( file: alwaysMigration, in: migrationsPath, usage: . migration)
68- }
69-
7063 // Queries can be compiled independently
7164 try await withThrowingTaskGroup ( of: Void . self) { group in
7265 for query in queriesFiles {
@@ -94,15 +87,8 @@ public actor Driver {
9487 . filter { $0. usage == . queries }
9588 . map { ( $0. fileName. split ( separator: " . " ) . first? . description, $0. statements) }
9689
97- let alwaysMigration = results. values
98- . first { $0. usage == . alwaysMigration } ?
99- . statements
100- . map ( \. sanitizedSource)
101- . joined ( )
102-
10390 let file = try Lang . generate (
10491 migrations: migrations,
105- alwaysMigration: alwaysMigration,
10692 queries: queries,
10793 schema: currentSchema,
10894 options: options
@@ -132,7 +118,7 @@ public actor Driver {
132118 compiler. schema = currentSchema
133119
134120 let diagnostics = switch usage {
135- case . migration, . alwaysMigration :
121+ case . migration:
136122 compiler. compile ( migration: fileContents, namespace: . global)
137123 case . queries:
138124 compiler. compile ( queries: fileContents, namespace: . global)
@@ -172,35 +158,19 @@ public actor Driver {
172158 " \( base) /Queries "
173159 }
174160
175- private func organizeMigrations (
161+ private func validateMigrations (
176162 fileNames: [ String ]
177- ) throws -> ( standard: [ String ] , always: String ? ) {
178- var standard : [ String ] = [ ]
179- var always : String ?
180-
163+ ) throws {
181164 for fileName in fileNames. sorted ( ) {
182- var components = fileName. split ( separator: " . " )
165+ let components = fileName. split ( separator: " . " )
183166
184167 guard components. count == 2 else {
185168 throw Error . invalidMigrationName ( fileName)
186169 }
187170
188- let nameWithoutExt = components [ 0 ]
189-
190- if Int ( nameWithoutExt) != nil {
191- standard. append ( fileName)
192- } else if nameWithoutExt == " Always " {
193- guard always == nil else {
194- // Can this really even happen?
195- throw Error . canOnlyHaveOneAlwaysMigration
196- }
197-
198- always = fileName
199- } else {
171+ if Int ( components [ 0 ] ) != nil {
200172 throw Error . invalidMigrationName ( fileName)
201173 }
202174 }
203-
204- return ( standard, always)
205175 }
206176}
0 commit comments