[chore] move inventory relationship to sku

This commit is contained in:
2026-04-07 09:52:17 -04:00
parent 5dc7ce2de7
commit cb829e1922
4 changed files with 34 additions and 31 deletions

View File

@@ -62,7 +62,7 @@ export const createCardCollection = async () => {
{ name: 'releaseDate', type: 'int32' },
{ name: 'marketPrice', type: 'int32', optional: true, sort: true },
{ name: 'content', type: 'string', token_separators: ['/'] },
{ name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true }
// { name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true }
],
});
console.log(chalk.green('Collection "cards" created successfully.'));
@@ -83,6 +83,7 @@ export const createSkuCollection = async () => {
{ name: 'highestPrice', type: 'int32', optional: true },
{ name: 'lowestPrice', type: 'int32', optional: true },
{ name: 'marketPrice', type: 'int32', optional: true },
{ name: 'card_id', type: 'string', reference: 'cards.id' },
]
});
console.log(chalk.green('Collection "skus" created successfully.'));
@@ -101,7 +102,7 @@ export const createInventoryCollection = async () => {
{ name: 'id', type: 'string' },
{ name: 'userId', type: 'string' },
{ name: 'catalogName', type: 'string' },
{ name: 'card_id', type: 'string', reference: 'cards.id' },
{ name: 'sku_id', type: 'string', reference: 'skus.id' },
]
});
console.log(chalk.green('Collection "inventories" created successfully.'));
@@ -132,7 +133,7 @@ export const upsertCardCollection = async (db:DBInstance) => {
content: [card.productName, card.productLineName, card.set?.setName || "", card.number, card.rarityName, card.artist || ""].join(' '),
releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0,
...(marketPrice !== null && { marketPrice }),
sku_id: card.prices.map(price => price.skuId.toString())
// sku_id: card.prices.map(price => price.skuId.toString())
};
}), { action: 'upsert' });
console.log(chalk.green('Collection "cards" indexed successfully.'));
@@ -146,6 +147,7 @@ export const upsertSkuCollection = async (db:DBInstance) => {
highestPrice: DollarToInt(sku.highestPrice),
lowestPrice: DollarToInt(sku.lowestPrice),
marketPrice: DollarToInt(sku.marketPrice),
card_id: sku.cardId.toString(),
})), { action: 'upsert' });
console.log(chalk.green('Collection "skus" indexed successfully.'));
}
@@ -156,7 +158,7 @@ export const upsertInventoryCollection = async (db:DBInstance) => {
id: i.inventoryId,
userId: i.userId,
catalogName: i.catalogName,
card_id: i.cardId.toString(),
sku_id: i.skuId.toString(),
})), { action: 'upsert' });
console.log(chalk.green('Collection "inventories" indexed successfully.'));
}