[chore] sales history schema
This commit is contained in:
@@ -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(),
|
||||||
|
|||||||
@@ -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(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user