|
- //
- // mdlTemplateItemSpec.swift
- //
- //
- // Created by Michiel Carman on 2/16/24.
- //
-
-
- import Fluent
- import Vapor
- import Foundation
- import FluentKit
-
- final class mdlTemplateItemSpec: Model, Content {
- static let schema = "templateItemSpec"
-
- @ID(custom: "id", generatedBy: .database) var id: Int?
-
- @Parent(key: "templateCategoryId") var templatecategory: mdlTemplateCategory
- @OptionalParent(key: "itemId") var item: mdlItem?
- @OptionalParent(key: "specId") var spec: mdlSpec?
-
- @Field(key: "sortOrder") var sortorder: Int?
-
- @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,
- categoryid: Int,
- itemid: Int? = nil,
- specid: Int? = nil,
- sortorder: Int? = 0,
- createuserid: Int? = nil,
- updateuserid: Int? = nil
- ) {
- self.id = id
- self.$templatecategory.$id.value = categoryid
- self.$item.$id.value = itemid
- self.$spec.$id.value = specid
- self.sortorder = sortorder
- self.createuserid = createuserid
- self.updateuserid = updateuserid
- }
- }
- extension mdlTemplateItemSpec{
- struct Create: AsyncMigration {
- func prepare(on database: Database) async throws {
- try await database.schema("templateItemSpec")
- .field("id", .int, .identifier(auto: true))
- .field("templateCategoryId", .int, .references("templateCategory", "id"))
- .field("itemId", .int, .references("item", "id"))
- .field("specId", .int, .references("spec", "id"))
- .field("sortOrder", .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("templateItemSpec").delete()
- }
- }
- }
|