25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

mdlCustomer.swift 1.8 KiB

2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // mdlCustomer.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 mdlCustomer: Model, Content {
  12. static let schema = "customer"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "name") var name: String?
  15. @Field(key: "number") var number: String?
  16. @Field(key: "isActive") var isactive: Bool?
  17. @Children(for: \.$customer) var contacts: [mdlContact]
  18. @Children(for: \.$customer) var workorders: [mdlWorkOrder]
  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, number: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) {
  25. self.id = id
  26. self.number = number
  27. self.isactive = isactive
  28. self.createuserid = createuserid
  29. self.updateuserid = updateuserid
  30. }
  31. }
  32. extension mdlCustomer{
  33. struct Create: AsyncMigration {
  34. func prepare(on database: Database) async throws {
  35. try await database.schema("customer")
  36. .field("id", .int, .identifier(auto: true))
  37. .field("name", .string)
  38. .field("number", .string)
  39. .field("isActive", .bool)
  40. .field("createDate", .datetime)
  41. .field("createUserId", .int)
  42. .field("updateDate", .datetime)
  43. .field("updateUserId", .int)
  44. .create()
  45. }
  46. func revert(on database: Database) async throws {
  47. try await database.schema("customer").delete()
  48. }
  49. }
  50. }