Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

72 linhas
2.1 KiB

  1. //
  2. // mdlModel.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 1/24/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. import Foundation
  10. import FluentKit
  11. final class mdlModel: Model, Content {
  12. static let schema = "model"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "name") var name: String?
  15. @Field(key: "description") var description: String?
  16. @Field(key: "isActive") var isactive: Bool?
  17. @Parent(key: "productId") var product: mdlProduct
  18. @Parent(key: "makeId") var make: mdlMake
  19. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  20. @Field(key: "createUserId") var createuserid: Int?
  21. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  22. @Field(key: "updateUserId") var updateuserid: Int?
  23. init() { }
  24. init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, productid: Int? = nil, makeid: Int? = nil) {
  25. self.id = id
  26. self.name = name
  27. self.description = description
  28. self.isactive = isactive
  29. self.$product.$id.value = productid!
  30. self.$make.$id.value = makeid!
  31. self.createuserid = createuserid
  32. self.updateuserid = updateuserid
  33. }
  34. }
  35. extension mdlModel{
  36. struct Create: AsyncMigration {
  37. func prepare(on database: Database) async throws {
  38. try await database.schema("model")
  39. .field("id", .int, .identifier(auto: true))
  40. .field("name", .string)
  41. .field("description", .string)
  42. .field("productId", .int, .references("product", "id"))
  43. .field("makeId", .int, .references("make", "id"))
  44. .field("isActive", .bool)
  45. .field("createDate", .datetime)
  46. .field("createUserId", .int)
  47. .field("updateDate", .datetime)
  48. .field("updateUserId", .int)
  49. .create()
  50. }
  51. func revert(on database: Database) async throws {
  52. try await database.schema("model").delete()
  53. }
  54. }
  55. }