// // File.swift // // // Created by Michiel Carman on 4/16/24. // import Fluent import Vapor final class mdlToken: Model, Content{ static let schema = "user_token" @ID(custom: "id", generatedBy: .database) var id: Int? @Field(key: "value") var value: String @Parent(key: "associateId") var user: mdlAssociate init(){} init(id: Int? = nil, value: String, userid: mdlAssociate.IDValue){ self.id = id self.value = value self.$user.id = userid } } extension mdlToken{ struct Create: AsyncMigration { var name: String { "CreateUserToken"} func prepare(on database: Database) async throws { try await database.schema("user_token") .field("id", .int, .identifier(auto: true)) .field("value", .string) .field("associateId", .int, .required, .references("associate", "id")) .unique(on: "value") .create() } func revert(on database: Database) async throws { try await database.schema("user_token").delete() } } } extension mdlToken: ModelTokenAuthenticatable{ static let valueKey = \mdlToken.$value static let userKey = \mdlToken.$user var isValid: Bool{true} }