vapor/sql-kit

Adding multiple enum cases discards items except one.

omochi opened this issue · 1 comments

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

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.

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.

    @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.