diff --git a/scripts/preload-tcgplayer.ts b/scripts/preload-tcgplayer.ts index 3d6571a..55e5498 100644 --- a/scripts/preload-tcgplayer.ts +++ b/scripts/preload-tcgplayer.ts @@ -148,10 +148,10 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s const detailData = await detailResponse.json(); - await db.insert(schema.cards).values({ + await db.insert(schema.tcgcards).values({ productId: item.productId, - originalProductName: item.productName, - productName: cleanProductName(item.productName), + productName: item.productName, + //productName: cleanProductName(item.productName), rarityName: item.rarityName, productLineName: item.productLineName, productLineUrlName: item.productLineUrlName, @@ -187,8 +187,8 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s Artist: detailData.formattedAttributes.Artist || null, }).onDuplicateKeyUpdate({ set: { - originalProductName: item.productName, - productName: cleanProductName(item.productName), + productName: item.productName, + //productName: cleanProductName(item.productName), rarityName: item.rarityName, productLineName: item.productLineName, productLineUrlName: item.productLineUrlName, diff --git a/scripts/reindex.ts b/scripts/reindex.ts index 928c2bb..bf28137 100644 --- a/scripts/reindex.ts +++ b/scripts/reindex.ts @@ -23,6 +23,7 @@ async function createCollection(client: Client) { name: 'cards', fields: [ { name: 'productId', type: 'int32' }, + { name: 'variant', type: 'string' }, { name: 'productName', type: 'string' }, { name: 'productLineName', type: 'string', facet: true }, { name: 'rarityName', type: 'string', facet: true }, @@ -33,7 +34,7 @@ async function createCollection(client: Client) { { name: 'Artist', type: 'string' }, { name: 'sealed', type: 'bool' }, ], - default_sorting_field: 'productId', + //default_sorting_field: 'productId', }); console.log(chalk.green('Collection "cards" created successfully.')); } else { @@ -54,6 +55,7 @@ async function preloadSearchIndex() { await client.collections('cards').documents().import(pokemon.map(card => ({ productId: card.productId, + variant: card.variant, productName: card.productName, productLineName: card.productLineName, rarityName: card.rarityName, diff --git a/src/db/relations.ts b/src/db/relations.ts index 2c3df63..a674e80 100644 --- a/src/db/relations.ts +++ b/src/db/relations.ts @@ -4,8 +4,8 @@ import * as schema from "./schema.ts"; export const relations = defineRelations(schema, (r) => ({ skus: { card: r.one.cards({ - from: r.skus.productId, - to: r.cards.productId, + from: [r.skus.productId, r.skus.variant], + to: [r.cards.productId, r.cards.variant], }), }, cards: { diff --git a/src/db/schema.ts b/src/db/schema.ts index 726d792..13ae4d7 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -1,8 +1,7 @@ import { mysqlTable, int, varchar, boolean, decimal, datetime, index } from "drizzle-orm/mysql-core" -export const cards = mysqlTable("cards", { +export const tcgcards = mysqlTable("tcgcards", { productId: int().primaryKey(), - originalProductName: varchar({ length: 255 }).default("").notNull(), productName: varchar({ length: 255 }).notNull(), productLineName: varchar({ length: 255 }).default("").notNull(), productLineUrlName: varchar({ length: 255 }).default("").notNull(), @@ -41,6 +40,39 @@ export const cards = mysqlTable("cards", { Artist: varchar({ length: 255 }), }); +export const cards = mysqlTable("cards", { + cardId: int().notNull().primaryKey().autoincrement(), + productId: int().notNull(), + variant: varchar({ length: 100 }).notNull(), + productName: varchar({ length: 255 }), + productLineName: varchar({ length: 255 }), + productUrlName: varchar({ length: 255 }).default("").notNull(), + rarityName: varchar({ length: 100 }), + sealed: boolean().default(false).notNull(), + setId: int(), + cardType: varchar({ length: 100 }), + energyType: varchar({ length: 100 }), + number: varchar({ length: 50 }), + Artist: varchar({ length: 255 }), +}, +(table) => [ + index("card_productIdIdx").on(table.productId, table.variant), +]); + +export const tcg_overrides = mysqlTable("tcg_overrides", { + productId: int().primaryKey(), + productName: varchar({ length: 255 }), + productLineName: varchar({ length: 255 }), + productUrlName: varchar({ length: 255 }).default("").notNull(), + rarityName: varchar({ length: 100 }), + sealed: boolean().default(false).notNull(), + setId: int(), + cardType: varchar({ length: 100 }), + energyType: varchar({ length: 100 }), + number: varchar({ length: 50 }), + Artist: varchar({ length: 255 }), +}); + export const sets = mysqlTable("sets", { setId: int().primaryKey(), setName: varchar({ length: 255 }).notNull(), @@ -50,6 +82,7 @@ export const sets = mysqlTable("sets", { export const skus = mysqlTable("skus", { skuId: int().primaryKey(), + cardId: int().default(0).notNull(), productId: int().notNull(), condition: varchar({ length: 255 }).notNull(), language: varchar({ length: 100 }).notNull(), @@ -61,7 +94,7 @@ export const skus = mysqlTable("skus", { priceCount: int(), }, (table) => [ - index("productIdIdx").on(table.productId), + index("productIdIdx").on(table.productId, table.variant), ]); export const processingSkus = mysqlTable("processingSkus", { diff --git a/src/pages/partials/card-modal.astro b/src/pages/partials/card-modal.astro index 94052f6..37a53e6 100644 --- a/src/pages/partials/card-modal.astro +++ b/src/pages/partials/card-modal.astro @@ -15,12 +15,12 @@ export const partial = true; export const prerender = false; const searchParams = Astro.url.searchParams; -const productId = Number(searchParams.get('productId')) || 0; +const cardId = Number(searchParams.get('cardId')) || 0; // query the database for the card with the given productId and return the card data as json const card = await db.query.cards.findFirst({ - where: { productId: Number(productId) }, + where: { cardId: Number(cardId) }, with: { prices: true, set: true, @@ -29,7 +29,8 @@ const card = await db.query.cards.findFirst({ const nearMint = await db.query.skus.findFirst({ where: { - productId: Number(productId), + productId: card?.productId || 0, + variant: card?.variant || "", } }); diff --git a/src/pages/partials/cards.astro b/src/pages/partials/cards.astro index 9e318e8..d1ac7b6 100644 --- a/src/pages/partials/cards.astro +++ b/src/pages/partials/cards.astro @@ -52,7 +52,7 @@ const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Hea
-