Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

74 rindas
2.2 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. @Children(for: \.$model) var templates: [mdlTemplate]
  20. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  21. @Field(key: "createUserId") var createuserid: Int?
  22. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  23. @Field(key: "updateUserId") var updateuserid: Int?
  24. init() { }
  25. 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) {
  26. self.id = id
  27. self.name = name
  28. self.description = description
  29. self.isactive = isactive
  30. self.$product.$id.value = productid!
  31. self.$make.$id.value = makeid!
  32. self.createuserid = createuserid
  33. self.updateuserid = updateuserid
  34. }
  35. }
  36. extension mdlModel{
  37. struct Create: AsyncMigration {
  38. func prepare(on database: Database) async throws {
  39. try await database.schema("model")
  40. .field("id", .int, .identifier(auto: true))
  41. .field("name", .string)
  42. .field("description", .string)
  43. .field("productId", .int, .references("product", "id"))
  44. .field("makeId", .int, .references("make", "id"))
  45. .field("isActive", .bool)
  46. .field("createDate", .datetime)
  47. .field("createUserId", .int)
  48. .field("updateDate", .datetime)
  49. .field("updateUserId", .int)
  50. .create()
  51. }
  52. func revert(on database: Database) async throws {
  53. try await database.schema("model").delete()
  54. }
  55. }
  56. }