Skip to content

Commit

Permalink
Copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Jan 23, 2025
1 parent 853ce6a commit d076d2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/storage/migrations/10-loot-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function up(db: Kysely<any>) {
}
}

export function createUpdatedAtTrigger(db: Kysely<any>, tableName: string) {
function createUpdatedAtTrigger(db: Kysely<any>, tableName: string) {
return sql
.raw(`
create trigger ${tableName}_updatedAt
Expand Down
15 changes: 14 additions & 1 deletion src/storage/migrations/11-fightsystem.ts
Original file line number Diff line number Diff line change
@@ -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<any>) {
await db.schema
Expand All @@ -26,6 +25,20 @@ export async function up(db: Kysely<any>) {
await createUpdatedAtTrigger(db, "fightHistory");
}

function createUpdatedAtTrigger(db: Kysely<any>, 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<any>) {
throw new Error("Not supported lol");
}

0 comments on commit d076d2a

Please sign in to comment.