|
- //
- // mdlTemplate.swift
- //
- //
- // Created by Michiel Carman on 2/16/24.
- //
-
-
- import Fluent
- import Vapor
- import Foundation
- import FluentKit
-
- final class mdlTemplate: Model, Content {
- static let schema = "template"
-
- @ID(custom: "id", generatedBy: .database) var id: Int?
-
- @OptionalParent(key: "inspectionLevelId") var level: mdlInspectionLevel?
- @OptionalParent(key: "productId") var product: mdlProduct?
- @OptionalParent(key: "makeId") var make: mdlMake?
- @OptionalParent(key: "modelId") var model: mdlModel?
- @OptionalParent(key: "customerId") var customer: mdlCustomer?
- @OptionalParent(key: "equipmentId") var equipment: mdlEquipment?
-
- @Children(for: \.$template) var categories: [mdlTemplateCategory]
-
- @Field(key: "name") var name: String?
- @Field(key: "description") var description: String?
- @Field(key: "isActive") var isactive: Bool?
-
- @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,
- levelid: Int? = nil,
- productid: Int? = nil,
- makeid: Int? = nil,
- modelid: Int? = nil,
- customerid: Int? = nil,
- equipmentid: Int? = nil,
- name: String? = nil,
- description: String? = nil,
- isactive: Bool? = true,
- createuserid: Int? = nil,
- updateuserid: Int? = nil
- ) {
- self.id = id
- self.$level.$id.value = levelid!
- self.$product.$id.value = productid!
- self.$make.$id.value = makeid!
- self.$model.$id.value = modelid!
- self.$customer.$id.value = customerid!
- self.$equipment.$id.value = equipmentid!
- self.name = name
- self.description = description
- self.isactive = isactive
- self.createuserid = createuserid
- self.updateuserid = updateuserid
- }
- }
- extension mdlTemplate{
- struct Create: AsyncMigration {
- func prepare(on database: Database) async throws {
- try await database.schema("template")
- .field("id", .int, .identifier(auto: true))
- .field("inspectionLevelId", .int, .references("inspectionLevel", "id"))
- .field("productId", .int, .references("product", "id"))
- .field("makeId", .int, .references("make", "id"))
- .field("modelId", .int, .references("model", "id"))
- .field("customerId", .int, .references("customer", "id"))
- .field("equipment", .int, .references("equipment", "id"))
- .field("name", .string)
- .field("description", .string)
- .field("isActive", .bool)
- .field("createDate", .datetime)
- .field("createUserId", .int)
- .field("updateDate", .datetime)
- .field("updateUserId", .int)
- .create()
- }
-
- func revert(on database: Database) async throws {
- try await database.schema("template").delete()
- }
- }
- struct Mod1: AsyncMigration {
- func prepare(on database: Database) async throws {
- try await database.schema("template")
- .deleteField("equipment")
- .field("equipmentId", .int, .references("equipment", "id"))
- .update()
- }
-
- func revert(on database: Database) async throws {
- try await database.schema("template")
- .deleteField("equipmentId")
- .field("equipment", .int, .references("equipment", "id"))
- .update()
- }
- }
- }
|