diff --git a/src/storage/migrations/10-loot-attributes.ts b/src/storage/migrations/10-loot-attributes.ts index 5cb0fb42..16cd9b6e 100644 --- a/src/storage/migrations/10-loot-attributes.ts +++ b/src/storage/migrations/10-loot-attributes.ts @@ -64,7 +64,7 @@ export async function up(db: Kysely) { } } -export function createUpdatedAtTrigger(db: Kysely, tableName: string) { +function createUpdatedAtTrigger(db: Kysely, tableName: string) { return sql .raw(` create trigger ${tableName}_updatedAt diff --git a/src/storage/migrations/11-fightsystem.ts b/src/storage/migrations/11-fightsystem.ts index d510fb5f..2705e5ed 100644 --- a/src/storage/migrations/11-fightsystem.ts +++ b/src/storage/migrations/11-fightsystem.ts @@ -1,5 +1,4 @@ import { sql, type Kysely } from "kysely"; -import { createUpdatedAtTrigger } from "@/storage/migrations/10-loot-attributes.js"; export async function up(db: Kysely) { await db.schema @@ -26,6 +25,20 @@ export async function up(db: Kysely) { await createUpdatedAtTrigger(db, "fightHistory"); } +function createUpdatedAtTrigger(db: Kysely, tableName: string) { + return sql + .raw(` + create trigger ${tableName}_updatedAt + after update on ${tableName} for each row + begin + update ${tableName} + set updatedAt = current_timestamp + where id = old.id; + end; + `) + .execute(db); +} + export async function down(_db: Kysely) { throw new Error("Not supported lol"); }