|
|
|
@@ -0,0 +1,86 @@ |
|
|
|
// |
|
|
|
// mdlSegment.swift |
|
|
|
// |
|
|
|
// |
|
|
|
// Created by Michiel Carman on 1/24/24. |
|
|
|
// |
|
|
|
|
|
|
|
import Fluent |
|
|
|
import Vapor |
|
|
|
import Foundation |
|
|
|
import FluentKit |
|
|
|
|
|
|
|
final class mdlSegment: Model, Content { |
|
|
|
static let schema = "segment" |
|
|
|
|
|
|
|
@ID(custom: "id", generatedBy: .database) var id: Int? |
|
|
|
|
|
|
|
@Field(key: "name") var name: String? |
|
|
|
@Field(key: "code") var code: String? |
|
|
|
@Field(key: "description") var description: String? |
|
|
|
@Field(key: "isActive") var isactive: Bool? |
|
|
|
|
|
|
|
@Siblings(through: mdlXWorkOrderSegment.self, from: \.$segment, to: \.$workorder) var workorders: [mdlWorkOrder] |
|
|
|
|
|
|
|
@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, code: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { |
|
|
|
self.id = id |
|
|
|
|
|
|
|
self.name = name |
|
|
|
self.code = code |
|
|
|
self.description = description |
|
|
|
self.isactive = isactive |
|
|
|
|
|
|
|
self.createuserid = createuserid |
|
|
|
self.updateuserid = updateuserid |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extension mdlSegment{ |
|
|
|
struct Create: AsyncMigration { |
|
|
|
func prepare(on database: Database) async throws { |
|
|
|
try await database.schema("segment") |
|
|
|
.field("id", .int, .identifier(auto: true)) |
|
|
|
.field("name", .string) |
|
|
|
.field("code", .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("segment").delete() |
|
|
|
} |
|
|
|
} |
|
|
|
struct Seed: Migration{ |
|
|
|
func prepare(on database: Database) -> EventLoopFuture<Void> { |
|
|
|
let mdls: [mdlSegment] = [ |
|
|
|
.init(id: nil, name: "Inspection", code: "0001", description: nil, createuserid: -1, updateuserid: -1), |
|
|
|
.init(id: nil, name: "Oil Sample", code: "0002", description: nil, createuserid: -1, updateuserid: -1), |
|
|
|
.init(id: nil, name: "Consumption", code: "0003", description: nil, createuserid: -1, updateuserid: -1), |
|
|
|
.init(id: nil, name: "Part", code: "0004", description: nil, createuserid: -1, updateuserid: -1) |
|
|
|
] |
|
|
|
return mdls.map { mdl in |
|
|
|
mdl.save(on: database) |
|
|
|
} |
|
|
|
.flatten(on: database.eventLoop) |
|
|
|
} |
|
|
|
|
|
|
|
func revert(on database: Database) -> EventLoopFuture<Void> { |
|
|
|
mdlSegment.query(on: database).delete() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|