Closed omochi closed 2 years ago
When I try to add multiple enum cases, fluent add only one case and silently discards other cases.
For example, with following migration
struct AddCases: Migration { func prepare(on database: Database) -> EventLoopFuture<Void> { return database.enum("myEnum") .case("foo") .case("bar") .case("baz") .update() .map { (_) in () } } }
After run it, only baz added to database and foo and bar are skipped.
baz
foo
bar
All cases added.
vapor 4.49.0 fluent-postgres-driver 2.2.0 sql-kit 3.10.0
I found wrong code. SQLAlterEnumBuilder only hold last one case.
SQLAlterEnumBuilder
@discardableResult public func add(value: SQLExpression) -> Self { self.alterEnum.value = value return self }
https://github.com/vapor/sql-kit/blob/main/Sources/SQLKit/Builders/SQLAlterEnumBuilder.swift#L28-L32
This is unfortunately deliberate, as the query syntax supported by PostgreSQL only allows adding a single enum case at a time.
Describe the bug
When I try to add multiple enum cases, fluent add only one case and silently discards other cases.
For example, with following migration
After run it, only
baz
added to database andfoo
andbar
are skipped.Expected behavior
All cases added.
Environment
vapor 4.49.0 fluent-postgres-driver 2.2.0 sql-kit 3.10.0
Additional context
I found wrong code.
SQLAlterEnumBuilder
only hold last one case.https://github.com/vapor/sql-kit/blob/main/Sources/SQLKit/Builders/SQLAlterEnumBuilder.swift#L28-L32