From d076d2ada407cb9df2186e8ac896fa85fece8492 Mon Sep 17 00:00:00 2001 From: holzmaster Date: Thu, 23 Jan 2025 15:10:07 +0100 Subject: [PATCH] Copy function --- src/storage/migrations/10-loot-attributes.ts | 2 +- src/storage/migrations/11-fightsystem.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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"); }