diff --git a/src/db/relations.ts b/src/db/relations.ts index 230a15a..218d423 100644 --- a/src/db/relations.ts +++ b/src/db/relations.ts @@ -8,12 +8,19 @@ export const relations = defineRelations(schema, (r) => ({ to: r.skus.skuId, }), }, + salesHistory: { + sku: r.one.skus({ + from: r.salesHistory.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(), + latestSales: r.many.salesHistory(), }, cards: { prices: r.many.skus(), diff --git a/src/db/schema.ts b/src/db/schema.ts index 94c1436..f947357 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -109,6 +109,21 @@ export const priceHistory = pokeSchema.table('price_history', { primaryKey({ name: 'pk_price_history', columns: [table.skuId, table.calculatedAt] }) ]); +export const salesHistory = pokeSchema.table('sales_history',{ + skuId: integer().notNull(), + orderDate: timestamp().notNull(), + title: varchar({ length: 255 }), + customListingId: varchar({ length: 255 }), + language: varchar({ length: 100 }), + listingType: varchar({ length: 100 }), + purchasePrice: decimal({ precision: 10, scale: 2 }), + quantity: integer(), + shippingPrice: decimal({ precision: 10, scale: 2 }) +}, +(table) => [ + primaryKey({ name: 'pk_sales_history', columns: [table.skuId, table.orderDate] }) +]); + export const processingSkus = pokeSchema.table('processing_skus', { skuId: integer().primaryKey(), });