Initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// CategoryModel.swift
|
||||
// ExodaiAcademy
|
||||
//
|
||||
// Created by Exodai on 23/01/2026.
|
||||
//
|
||||
|
||||
import Fluent
|
||||
|
||||
final class CategoryModel: Model, @unchecked Sendable {
|
||||
static let schema: String = Database.categories.rawValue
|
||||
|
||||
// MARK: - ID
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
// MARK: - Data
|
||||
|
||||
@Field(key: FieldKeys.name)
|
||||
var name: String
|
||||
|
||||
// MARK: - Initializers
|
||||
|
||||
init() {}
|
||||
|
||||
init(
|
||||
id: UUID? = nil,
|
||||
name: String
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
|
||||
extension CategoryModel {
|
||||
struct FieldKeys {
|
||||
static var name: FieldKey { "name" }
|
||||
}
|
||||
}
|
||||
|
||||
extension CategoryModel {
|
||||
struct Migration: AsyncMigration {
|
||||
|
||||
func prepare(on database: any FluentKit.Database) async throws {
|
||||
try await database.schema(CategoryModel.schema)
|
||||
.id()
|
||||
.field(FieldKeys.name, .string, .required)
|
||||
.unique(on: FieldKeys.name)
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: any FluentKit.Database) async throws {
|
||||
try await database.schema(CategoryModel.schema).delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user