[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";
|
import * as schema from "./schema.ts";
|
||||||
|
|
||||||
export const relations = defineRelations(schema, (r) => ({
|
export const relations = defineRelations(schema, (r) => ({
|
||||||
|
priceHistory: {
|
||||||
|
sku: r.one.skus({
|
||||||
|
from: r.priceHistory.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(),
|
||||||
},
|
},
|
||||||
cards: {
|
cards: {
|
||||||
prices: r.many.skus(),
|
prices: r.many.skus(),
|
||||||
|
|||||||
@@ -97,6 +97,15 @@ export const skus = mysqlTable("skus", {
|
|||||||
index("productIdIdx").on(table.productId, table.variant),
|
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", {
|
export const processingSkus = mysqlTable("processingSkus", {
|
||||||
skuId: int().primaryKey(),
|
skuId: int().primaryKey(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user