73 lines
1.9 KiB
Swift
73 lines
1.9 KiB
Swift
//
|
|
// LogModel.swift
|
|
// ExodaiAcademy
|
|
//
|
|
// Created by Exodai on 24/01/2026.
|
|
//
|
|
|
|
import Fluent
|
|
|
|
final class LogModel: Model, @unchecked Sendable {
|
|
static let schema: String = Database.logs.rawValue
|
|
|
|
@ID(key: .id)
|
|
var id: UUID?
|
|
|
|
@Field(key: FieldKeys.event)
|
|
var event: String
|
|
|
|
@OptionalField(key: FieldKeys.actorID)
|
|
var actorID: UserModel.IDValue?
|
|
|
|
@OptionalField(key: FieldKeys.targetType)
|
|
var targetType: String?
|
|
|
|
@OptionalField(key: FieldKeys.targetID)
|
|
var targetID: UUID?
|
|
|
|
@OptionalField(key: FieldKeys.context)
|
|
var context: String?
|
|
|
|
@OptionalField(key: FieldKeys.ipAddress)
|
|
var ipAddress: String?
|
|
|
|
@Timestamp(key: FieldKeys.createdAt, on: .create)
|
|
var createdAt: Date?
|
|
|
|
init() {}
|
|
}
|
|
|
|
extension LogModel {
|
|
struct FieldKeys {
|
|
static var event: FieldKey { "event" }
|
|
static var actorID: FieldKey { "actorID" }
|
|
static var ipAddress: FieldKey { "ipAddress" }
|
|
static var targetType: FieldKey { "targetType" }
|
|
static var targetID: FieldKey { "targetID" }
|
|
static var context: FieldKey { "context" }
|
|
static var createdAt: FieldKey { "createdAt" }
|
|
}
|
|
}
|
|
|
|
extension LogModel {
|
|
struct Migration: AsyncMigration {
|
|
|
|
func prepare(on database: any FluentKit.Database) async throws {
|
|
try await database.schema(LogModel.schema)
|
|
.id()
|
|
.field(FieldKeys.event, .string, .required)
|
|
.field(FieldKeys.actorID, .uuid)
|
|
.field(FieldKeys.ipAddress, .string)
|
|
.field(FieldKeys.targetType, .string)
|
|
.field(FieldKeys.targetID, .uuid)
|
|
.field(FieldKeys.context, .string)
|
|
.field(FieldKeys.createdAt, .datetime)
|
|
.create()
|
|
}
|
|
|
|
func revert(on database: any FluentKit.Database) async throws {
|
|
try await database.schema(LogModel.schema).delete()
|
|
}
|
|
}
|
|
}
|