|
- //
- // mdlInspectionLevel.swift
- //
- //
- // Created by Michiel Carman on 2/16/24.
- //
-
-
- import Fluent
- import Vapor
- import Foundation
- import FluentKit
-
- final class mdlInspectionLevel: Model, Content {
- static let schema = "inspectionLevel"
-
- @ID(custom: "id", generatedBy: .database) var id: Int?
-
- @Field(key: "name") var name: String?
- @Field(key: "description") var description: String?
- @Field(key: "isActive") var isactive: Bool?
- @Parent(key: "inspectionTypeId") var inspectiontype: mdlInspectionType
- @Children(for: \.$level) var inspections: [mdlInspection]
- @Children(for: \.$level) var templates: [mdlTemplate]
-
- @Timestamp(key: "createDate", on: .create) var createdate: Date?
- @Field(key: "createUserId") var createuserid: Int?
- @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
- @Field(key: "updateUserId") var updateuserid: Int?
-
- init() { }
-
- init(id: Int? = nil,
- name: String? = nil,
- description: String? = nil,
- isactive: Bool? = true,
- inspectiontypeid: Int,
- createuserid: Int? = nil,
- updateuserid: Int? = nil
- ) {
- self.id = id
- self.name = name
- self.description = description
- self.isactive = isactive
- self.$inspectiontype.$id.value = inspectiontypeid
- self.createuserid = createuserid
- self.updateuserid = updateuserid
- }
- }
- extension mdlInspectionLevel{
- struct Create: AsyncMigration {
- func prepare(on database: Database) async throws {
- try await database.schema("inspectionLevel")
- .field("id", .int, .identifier(auto: true))
- .field("name", .string)
- .field("description", .string)
- .field("isactive", .bool)
- .field("inspectionTypeId", .int)
- .field("createDate", .datetime)
- .field("createUserId", .int)
- .field("updateDate", .datetime)
- .field("updateUserId", .int)
- .create()
- }
-
- func revert(on database: Database) async throws {
- try await database.schema("inspectionLevel").delete()
- }
- }
- }
|