From 1089bcdc209150d32725c543e5b8d6410047bdf3 Mon Sep 17 00:00:00 2001 From: Thad Miller Date: Mon, 9 Mar 2026 15:43:37 -0400 Subject: [PATCH] [chore] schema for price history --- src/db/relations.ts | 7 +++++++ src/db/schema.ts | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/db/relations.ts b/src/db/relations.ts index 73c0bf6..230a15a 100644 --- a/src/db/relations.ts +++ b/src/db/relations.ts @@ -2,11 +2,18 @@ import { defineRelations } from "drizzle-orm"; import * as schema from "./schema.ts"; export const relations = defineRelations(schema, (r) => ({ + priceHistory: { + sku: r.one.skus({ + from: r.priceHistory.skuId, + to: r.skus.skuId, + }), + }, skus: { card: r.one.cards({ from: [r.skus.productId, r.skus.variant], to: [r.cards.productId, r.cards.variant], }), + history: r.many.priceHistory(), }, cards: { prices: r.many.skus(), diff --git a/src/db/schema.ts b/src/db/schema.ts index 13ae4d7..9685f20 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -97,6 +97,15 @@ export const skus = mysqlTable("skus", { index("productIdIdx").on(table.productId, table.variant), ]); +export const priceHistory = mysqlTable("price_history", { + skuId: int().default(0).notNull(), + calculatedAt: datetime(), + marketPrice: decimal({ precision: 10, scale: 2 }), +}, +(table) => [ + index("idx_price_history").on(table.skuId, table.calculatedAt), +]); + export const processingSkus = mysqlTable("processingSkus", { skuId: int().primaryKey(), });