Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

94 строки
2.8 KiB

  1. //
  2. // mdlContact.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 mdlContact: Model, Content {
  12. static let schema = "contact"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "firstName") var firstname: String?
  15. @Field(key: "lastName") var lastname: String?
  16. @Field(key: "description") var description: String?
  17. @Field(key: "isActive") var isactive: Bool?
  18. @Parent(key: "customerId") var customer: mdlCustomer
  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, firstname: String? = nil, lastname: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, customerid: Int? = nil) {
  25. self.id = id
  26. self.firstname = firstname
  27. self.lastname = lastname
  28. self.isactive = isactive
  29. self.$customer.$id.value = customerid!
  30. self.createuserid = createuserid
  31. self.updateuserid = updateuserid
  32. }
  33. }
  34. extension mdlContact{
  35. struct Create: AsyncMigration {
  36. func prepare(on database: Database) async throws {
  37. try await database.schema("contact")
  38. .field("id", .int, .identifier(auto: true))
  39. .field("firstName", .string)
  40. .field("lastName", .string)
  41. .field("isActive", .bool)
  42. .field("createDate", .datetime)
  43. .field("createUserId", .int)
  44. .field("updateDate", .datetime)
  45. .field("updateUserId", .int)
  46. .create()
  47. }
  48. func revert(on database: Database) async throws {
  49. try await database.schema("contact").delete()
  50. }
  51. }
  52. struct makeParentCustomer: AsyncMigration{
  53. func prepare(on database: Database) async throws {
  54. try await database.schema("contact")
  55. .field("customerId", .int, .references("customer", "id"))
  56. .update()
  57. }
  58. func revert(on database: Database) async throws {
  59. try await database.schema("contact")
  60. .deleteField("customerId" )
  61. .update()
  62. }
  63. }
  64. struct Mod1: AsyncMigration{
  65. func prepare(on database: Database) async throws {
  66. try await database.schema("contact")
  67. .field("description", .string)
  68. .update()
  69. }
  70. func revert(on database: Database) async throws {
  71. try await database.schema("contact")
  72. .deleteField("description" )
  73. .update()
  74. }
  75. }
  76. }