|
|
|
@@ -0,0 +1,105 @@ |
|
|
|
// |
|
|
|
// mdlSysUnit.swift |
|
|
|
// |
|
|
|
// |
|
|
|
// Created by Michiel Carman on 2/16/24. |
|
|
|
// |
|
|
|
|
|
|
|
|
|
|
|
import Fluent |
|
|
|
import Vapor |
|
|
|
import Foundation |
|
|
|
import FluentKit |
|
|
|
|
|
|
|
final class mdlSysCategory: Model, Content { |
|
|
|
static let schema = "sysCategory" |
|
|
|
|
|
|
|
@ID(custom: "id", generatedBy: .database) var id: Int? |
|
|
|
|
|
|
|
@Field(key: "name") var name: String? |
|
|
|
@Field(key: "description") var description: String? |
|
|
|
|
|
|
|
@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, |
|
|
|
createuserid: Int? = nil, |
|
|
|
updateuserid: Int? = nil |
|
|
|
) { |
|
|
|
self.id = id |
|
|
|
self.name = name |
|
|
|
self.description = description |
|
|
|
self.createuserid = createuserid |
|
|
|
self.updateuserid = updateuserid |
|
|
|
} |
|
|
|
} |
|
|
|
extension mdlSysCategory{ |
|
|
|
struct Create: AsyncMigration { |
|
|
|
func prepare(on database: Database) async throws { |
|
|
|
try await database.schema("sysCategory") |
|
|
|
.field("id", .int, .identifier(auto: true)) |
|
|
|
.field("name", .string) |
|
|
|
.field("description", .string) |
|
|
|
.field("createDate", .datetime) |
|
|
|
.field("createUserId", .int) |
|
|
|
.field("updateDate", .datetime) |
|
|
|
.field("updateUserId", .int) |
|
|
|
.create() |
|
|
|
} |
|
|
|
|
|
|
|
func revert(on database: Database) async throws { |
|
|
|
try await database.schema("sysCategory").delete() |
|
|
|
} |
|
|
|
} |
|
|
|
struct Seed: AsyncMigration{ |
|
|
|
func prepare(on database: FluentKit.Database) async throws { |
|
|
|
let mdls: [mdlSysCategory] = [ |
|
|
|
.init(id: 1, |
|
|
|
name: "LENGTH", |
|
|
|
description: "Unit of distance.", |
|
|
|
createuserid: -1, |
|
|
|
updateuserid: -1), |
|
|
|
.init(id: 1, |
|
|
|
name: "WEIGHT", |
|
|
|
description: "Unit of force.", |
|
|
|
createuserid: -1, |
|
|
|
updateuserid: -1), |
|
|
|
.init(id: 1, |
|
|
|
name: "CAPACITY", |
|
|
|
description: "Unit of capacity.", |
|
|
|
createuserid: -1, |
|
|
|
updateuserid: -1), |
|
|
|
.init(id: 1, |
|
|
|
name: "VOLUME", |
|
|
|
description: "Unit of volume.", |
|
|
|
createuserid: -1, |
|
|
|
updateuserid: -1), |
|
|
|
.init(id: 1, |
|
|
|
name: "AREA", |
|
|
|
description: "Unit of area.", |
|
|
|
createuserid: -1, |
|
|
|
updateuserid: -1), |
|
|
|
.init(id: 1, |
|
|
|
name: "TEMPERATURE", |
|
|
|
description: "Unit of temperature.", |
|
|
|
createuserid: -1, |
|
|
|
updateuserid: -1) |
|
|
|
] |
|
|
|
for mdl in mdls{ |
|
|
|
try await mdl.save(on: database) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func revert(on database: Database) async throws { |
|
|
|
try await mdlSysCategory.query(on: database).delete() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|