You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.
I’d like to encode an array of enums, but get the following error during migration:
Fatal error: Error raised at top level: ⚠️ PostgreSQL Error: column "priviliges" is of type jsonb[] but expression is of type smallint[] - id: PostgreSQLError.server.error.transformAssignedExpr
Any help would be appreciated, thank you.
reproduce with:
import Foundation
import Foundation
import Authentication
import FluentPostgreSQL
import Crypto
enum Privilege: UInt8, Codable {
case createPost,
updateOtherUserPost,
createTopic,
adminUsers
static var allPriviliges: [Privilege] {
get {
return [
.createPost,
.updateOtherUserPost,
.createTopic,
.adminUsers
]
}
}
}
You’ll need a basic User with id, email, username, password, and privs: [Privilege].
struct AdminUser: Migration {
typealias Database = PostgreSQLDatabase
static func prepare(on conn: PostgreSQLConnection) -> EventLoopFuture<Void> {
let adminUsername = Environment.get("ADMIN_USER")
let adminEmail = Environment.get("ADMIN_EMAIL")
let envPassword = Environment.get("ADMIN_PASSWORD")
guard let password = envPassword, password.count > 7,
let username = adminUsername,
let email = adminEmail
else {
fatalError("Required Admin values not set in environment")
}
let maybeEncryptedPassword = try? BCrypt.hash(password)
guard let encryptedPassword = maybeEncryptedPassword else {
fatalError("Admin password could not be encrypted")
}
let admin = User(id: nil,
email: email,
username: username,
password: encryptedPassword,
privs: Privilege.allPriviliges)
return admin.save(on: conn).transform(to: ())
}
static func revert(on conn: PostgreSQLConnection) -> EventLoopFuture<Void> {
return .done(on: conn)
}
}
Things attempted:
change enum type to String, Codable, Uint, Codable. Using just privs: [. adminUsers] in User().
The text was updated successfully, but these errors were encountered:
I’d like to encode an array of enums, but get the following error during migration:
Fatal error: Error raised at top level: ⚠️ PostgreSQL Error: column "priviliges" is of type jsonb[] but expression is of type smallint[]
- id: PostgreSQLError.server.error.transformAssignedExpr
Any help would be appreciated, thank you.
reproduce with:
You’ll need a basic
User
with id, email, username, password, andprivs: [Privilege]
.Things attempted:
change enum type to
String, Codable
,Uint, Codable
. Using justprivs: [. adminUsers]
inUser()
.The text was updated successfully, but these errors were encountered: