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

106 строки
3.3 KiB

  1. //
  2. // mdlSysUnit.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 2/16/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. import Foundation
  10. import FluentKit
  11. final class mdlSysCategory: Model, Content {
  12. static let schema = "sysCategory"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "name") var name: String?
  15. @Field(key: "description") var description: String?
  16. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  17. @Field(key: "createUserId") var createuserid: Int?
  18. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  19. @Field(key: "updateUserId") var updateuserid: Int?
  20. init() { }
  21. init(id: Int? = nil,
  22. name: String? = nil,
  23. description: String? = nil,
  24. createuserid: Int? = nil,
  25. updateuserid: Int? = nil
  26. ) {
  27. self.id = id
  28. self.name = name
  29. self.description = description
  30. self.createuserid = createuserid
  31. self.updateuserid = updateuserid
  32. }
  33. }
  34. extension mdlSysCategory{
  35. struct Create: AsyncMigration {
  36. func prepare(on database: Database) async throws {
  37. try await database.schema("sysCategory")
  38. .field("id", .int, .identifier(auto: true))
  39. .field("name", .string)
  40. .field("description", .string)
  41. .field("createDate", .datetime)
  42. .field("createUserId", .int)
  43. .field("updateDate", .datetime)
  44. .field("updateUserId", .int)
  45. .create()
  46. }
  47. func revert(on database: Database) async throws {
  48. try await database.schema("sysCategory").delete()
  49. }
  50. }
  51. struct Seed: AsyncMigration{
  52. func prepare(on database: FluentKit.Database) async throws {
  53. let mdls: [mdlSysCategory] = [
  54. .init(id: 1,
  55. name: "LENGTH",
  56. description: "Unit of distance.",
  57. createuserid: -1,
  58. updateuserid: -1),
  59. .init(id: 1,
  60. name: "WEIGHT",
  61. description: "Unit of force.",
  62. createuserid: -1,
  63. updateuserid: -1),
  64. .init(id: 1,
  65. name: "CAPACITY",
  66. description: "Unit of capacity.",
  67. createuserid: -1,
  68. updateuserid: -1),
  69. .init(id: 1,
  70. name: "VOLUME",
  71. description: "Unit of volume.",
  72. createuserid: -1,
  73. updateuserid: -1),
  74. .init(id: 1,
  75. name: "AREA",
  76. description: "Unit of area.",
  77. createuserid: -1,
  78. updateuserid: -1),
  79. .init(id: 1,
  80. name: "TEMPERATURE",
  81. description: "Unit of temperature.",
  82. createuserid: -1,
  83. updateuserid: -1)
  84. ]
  85. for mdl in mdls{
  86. try await mdl.save(on: database)
  87. }
  88. }
  89. func revert(on database: Database) async throws {
  90. try await mdlSysCategory.query(on: database).delete()
  91. }
  92. }
  93. }