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