|
- //
- // File.swift
- //
- //
- // Created by Michiel Carman on 11/2/21.
- //
-
- import Foundation
- import Vapor
- import Fluent
- import FluentPostgresDriver
-
- final class mdlCPCLTemplate: Model, Content{
-
- static let schema = "CPCLTemplate"
-
- @ID(custom: "id", generatedBy: .database) var id: Int?
- @Field(key: "name") var name: String
- @Field(key: "isActive") var isactive: Bool
- @Field(key: "createUserId" ) var createuserid: Int?
- @Timestamp(key: "createDate", on: .create) var createdate: Date?
- @Field(key: "updateUserId") var updateuserid: Int?
- @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
-
- //@Parent(key: "userId") var user: mdlUser
- @Parent(key: "oilSampleLabelId") var oilsamplelabel: mdlOilSampleLabel
-
- @Children(for: \.$cpcltemplate) var commands: [mdlCPCLTemplateCommand]
-
- init(){}
-
- init(id: Int?){
- self.id = id
- self.isactive = true
- self.createuserid = -1
- self.updateuserid = -1
- self.$oilsamplelabel.id = -1
- }
-
- init(name: String){
- self.name = name
- self.isactive = true
- self.createuserid = -1
- self.updateuserid = -1
- self.$oilsamplelabel.id = mdlOilSampleLabel(id: 1).id!
- }
-
- init(id: Int? = nil, name: String, isactive: Bool, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, oilsamplelabel: mdlOilSampleLabel, commands: [mdlCPCLTemplateCommand]?){
- self.id = id
- self.name = name
- self.isactive = isactive
- self.createuserid = createuserid
- self.createdate = createdate
- self.updateuserid = updateuserid
- self.updatedate = updatedate
- self.$oilsamplelabel.id = oilsamplelabel.id!
- }
- }
- extension mdlCPCLTemplate {
- struct Input: Content{
- let id: Int?
- let name: String
- let isactive: Bool
- let createdate: Date?
- let createuserid: Int?
- let updatedate: Date?
- let updateuserid: Int?
- let oilsamplelabel: mdlOilSampleLabel
- let commands: [mdlCPCLTemplateCommand]?
- }
-
- struct Output: Content{
- let id: Int?
- let name: String
- let isactive: Bool
- let createdate: Date?
- let createuserid: Int?
- let updatedate: Date?
- let updateuserid: Int?
- let oilsamplelabel: mdlOilSampleLabel
- let commands: [mdlCPCLTemplateCommand]?
- }
- struct create: Migration{
- func prepare(on database: Database) -> EventLoopFuture<Void> {
- return database.schema("CPCLTemplate")
- .field("id", .int, .identifier(auto: true))
- .field("name", .string)
- .field("isActive", .bool)
- .field("oilSampleLabelId", .int, .required, .references("OilSampleLabel", "id"))
- .field("createUserId", .int)
- .field("createDate", .datetime)
- .field("updateUserId", .int)
- .field("updateDate", .datetime)
- .create()
- }
- func revert(on database: Database) -> EventLoopFuture<Void> {
- database.schema("CPCLTemplate").delete()
- }
- }
- // Uncomment if you need to seed the table.
- struct seed: Migration {
- func prepare(on database: Database) -> EventLoopFuture<Void> {
- // 1
- let array: [mdlCPCLTemplate] = [
- .init(name: "Default")
- ]
- // 2
- return array.map { obj in
- obj.save(on: database)
- }
- .flatten(on: database.eventLoop)
- }
-
- func revert(on database: Database) -> EventLoopFuture<Void> {
- // 3
- mdlCPCLTemplate.query(on: database).delete()
- }
- }
- //
- }
|