From 29899acc7f43d35b410277c2db7d32b2a1a986a8 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Sat, 13 Dec 2025 12:00:02 +0100 Subject: [PATCH] feat: update database schema to support item trading --- src/db/schema.ts | 31 +++++++++++++++++++++++++++++++ src/graphics/studentID.ts | 1 - 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/db/schema.ts b/src/db/schema.ts index 6bb68e4..1aa6b3b 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -72,12 +72,28 @@ export const transactions = pgTable('transactions', { id: bigserial('id', { mode: 'bigint' }).primaryKey(), userId: bigint('user_id', { mode: 'bigint' }) .references(() => users.id, { onDelete: 'cascade' }), + relatedUserId: bigint('related_user_id', { mode: 'bigint' }) + .references(() => users.id, { onDelete: 'set null' }), amount: bigint('amount', { mode: 'bigint' }).notNull(), type: varchar('type', { length: 50 }).notNull(), description: text('description'), createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), }); +export const itemTransactions = pgTable('item_transactions', { + id: bigserial('id', { mode: 'bigint' }).primaryKey(), + userId: bigint('user_id', { mode: 'bigint' }) + .references(() => users.id, { onDelete: 'cascade' }).notNull(), + relatedUserId: bigint('related_user_id', { mode: 'bigint' }) + .references(() => users.id, { onDelete: 'set null' }), // who they got it from/gave it to + itemId: integer('item_id') + .references(() => items.id, { onDelete: 'cascade' }).notNull(), + quantity: bigint('quantity', { mode: 'bigint' }).notNull(), // positive = gain, negative = loss + type: varchar('type', { length: 50 }).notNull(), // e.g., 'TRADE', 'SHOP_BUY', 'DROP' + description: text('description'), + createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), +}); + // 6. Quests export const quests = pgTable('quests', { id: serial('id').primaryKey(), @@ -169,4 +185,19 @@ export const cooldownsRelations = relations(cooldowns, ({ one }) => ({ fields: [cooldowns.userId], references: [users.id], }), +})); + +export const itemTransactionsRelations = relations(itemTransactions, ({ one }) => ({ + user: one(users, { + fields: [itemTransactions.userId], + references: [users.id], + }), + relatedUser: one(users, { + fields: [itemTransactions.relatedUserId], + references: [users.id], + }), + item: one(items, { + fields: [itemTransactions.itemId], + references: [items.id], + }), })); \ No newline at end of file diff --git a/src/graphics/studentID.ts b/src/graphics/studentID.ts index 1b5e05a..22b439f 100644 --- a/src/graphics/studentID.ts +++ b/src/graphics/studentID.ts @@ -29,7 +29,6 @@ export async function generateStudentIdCard(data: StudentCardData): Promise