From 199bd0ebcce89fa6480de019f496f2a4ef741de5 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 28 Apr 2024 15:02:03 -0500 Subject: [PATCH] Fix enums (#2) We're mishandling enums in all three database types here. Fix it. --- Sources/QueuesFluentDriver/JobModelMigrate.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/QueuesFluentDriver/JobModelMigrate.swift b/Sources/QueuesFluentDriver/JobModelMigrate.swift index 2681a36..690c1da 100644 --- a/Sources/QueuesFluentDriver/JobModelMigrate.swift +++ b/Sources/QueuesFluentDriver/JobModelMigrate.swift @@ -7,17 +7,20 @@ public struct JobModelMigration: AsyncSQLMigration { // See `AsyncSQLMigration.prepare(on:)`. public func prepare(on database: any SQLDatabase) async throws { - let stateEnumType = "\(JobModel.schema)_StoredJobStatus" + let stateEnumType: String switch database.dialect.enumSyntax { case .typeName: + stateEnumType = "\(JobModel.schema)_storedjobstatus" try await database.create(enum: stateEnumType) .value("pending") .value("processing") .value("completed") .run() + case .inline: + stateEnumType = "enum(\(StoredJobState.allCases.map(\.rawValue).joined(separator: ",")))" default: - break + stateEnumType = "varchar(16)" } try await database.create(table: JobModel.schema) @@ -45,7 +48,7 @@ public struct JobModelMigration: AsyncSQLMigration { try await database.drop(table: JobModel.schema).run() switch database.dialect.enumSyntax { case .typeName: - try await database.drop(enum: "\(JobModel.schema)_StoredJobStatus").run() + try await database.drop(enum: "\(JobModel.schema)_storedjobstatus").run() default: break }