[chore] sales history schema

This commit is contained in:
2026-03-18 11:14:19 -04:00
parent ee9f7a2561
commit 2a17654c74
2 changed files with 22 additions and 0 deletions

View File

@@ -8,12 +8,19 @@ export const relations = defineRelations(schema, (r) => ({
to: r.skus.skuId, to: r.skus.skuId,
}), }),
}, },
salesHistory: {
sku: r.one.skus({
from: r.salesHistory.skuId,
to: r.skus.skuId,
}),
},
skus: { skus: {
card: r.one.cards({ card: r.one.cards({
from: [r.skus.productId, r.skus.variant], from: [r.skus.productId, r.skus.variant],
to: [r.cards.productId, r.cards.variant], to: [r.cards.productId, r.cards.variant],
}), }),
history: r.many.priceHistory(), history: r.many.priceHistory(),
latestSales: r.many.salesHistory(),
}, },
cards: { cards: {
prices: r.many.skus(), prices: r.many.skus(),

View File

@@ -109,6 +109,21 @@ export const priceHistory = pokeSchema.table('price_history', {
primaryKey({ name: 'pk_price_history', columns: [table.skuId, table.calculatedAt] }) 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', { export const processingSkus = pokeSchema.table('processing_skus', {
skuId: integer().primaryKey(), skuId: integer().primaryKey(),
}); });