-
-
Notifications
You must be signed in to change notification settings - Fork 55
Closed
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Description
Thank you for providing this excellent framework! 🚀
Describe the bug
Adding multiple new cases to an already existing enum does only add the last case before the update()
call.
To Reproduce
- Add an enum
struct Migration1: AsyncMigration {
let name = "CreateTaskType"
func prepare(on database: Database) async throws {
let taskType = try await database.enum(TaskType.schema)
.case(TaskType.simple.rawValue)
.create()
}
func revert(on database: Database) async throws {
try await database.enum(TaskType.schema)
.delete()
}
}
- Extend the enum in a second migration
struct Migration2: AsyncMigration {
let name = "AddMoreTaskTypes"
func prepare(on database: Database) async throws {
let taskTypeExtended = try await database.enum(TaskType.schema)
.case(TaskType.singleChoice.rawValue) // this does not get added.
.case(TaskType.multipleChoice.rawValue)
.update()
}
func revert(on database: Database) async throws {
// none
}
}
- The migration goes through fine. But when I try to add a model with the .singleChoice type in it. This returns
failed: caught error: "server: invalid input value for enum task_type: "singleChoice" (enum_in)"
When then checking in the PostgreSQL schema, only the last case before the update has been added.
Expected behavior
I expected to be able to add multiple enum cases to an existing enum with a migration like database.enum().case().case().case().update()
.
Environment
- Vapor Framework version: 4.55.0
- Vapor Toolbox version: 18.3.3
- OS version: macOS 12.2.1 (21D62)
Additional context
A workaround is to do the migration like this:
struct Migration2: AsyncMigration {
let name = "AddMoreTaskTypes"
func prepare(on database: Database) async throws {
_ = try await database.enum(TaskType.schema)
.case(TaskType.singleChoice.rawValue)
.update()
_ = try await database.enum(TaskType.schema)
.case(TaskType.multipleChoice.rawValue)
.update()
}
func revert(on database: Database) async throws {
// none
}
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers