vapor / fluent-postgres-driver

🐘 PostgreSQL driver for Fluent.
MIT License
149 stars 53 forks source link

String backed enum translates to jsonb in PostgreSQL instead of enum type #104

Closed iteroji closed 5 years ago

iteroji commented 5 years ago

I cannot figure out what I'm doing wrong but my string enum is not being translated into enum type but jsonb.

enum UserRole: String, PostgreSQLEnum {
    case  user, admin, superadmin
}

I get the following error: PostgreSQLError.server.error.report_invalid_token: invalid input syntax for type json

When I create the type in psql manually CREATE TYPE userRole AS ENUM ('user', 'admin', 'superadmin'); it starts working. Is there a way to automatically create the native postgres enum?

calebkleveter commented 5 years ago

Try conforming your enum to Migration and adding it to your migration config. Postgres should then create the enum in the database.

iteroji commented 5 years ago

Brilliant, I conformed the enum to PostgreSQLMigration and then added it to the config

migrations.add(migration: UserRole.self, database: .psql)

and magically works. Thanks 👍

calebkleveter commented 5 years ago

Awesome!