feat(33-01): add market_prices, community_prices tables and currency columns

- Add marketPrices table with unique(globalItemId, market, currency) constraint
- Add communityPrices table with unique(globalItemId, userId, sourceType) constraint
- Add priceCurrency column to items table (default EUR)
- Add foundPriceCents, foundPriceCurrency, foundPriceDate to threadCandidates
- Add Zod schemas for market price upsert and community price submission
- Export new types from shared/types.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 18:02:00 +02:00
parent 1d15d4b336
commit 298fa6d586
3 changed files with 77 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import {
boolean,
doublePrecision,
integer,
pgTable,
@@ -56,6 +57,7 @@ export const items = pgTable("items", {
quantity: integer("quantity").notNull().default(1),
globalItemId: integer("global_item_id").references(() => globalItems.id),
purchasePriceCents: integer("purchase_price_cents"),
priceCurrency: text("price_currency").default("EUR"),
brand: text("brand"),
dominantColor: text("dominant_color"),
cropZoom: doublePrecision("crop_zoom"),
@@ -108,6 +110,9 @@ export const threadCandidates = pgTable("thread_candidates", {
cons: text("cons"),
sortOrder: doublePrecision("sort_order").notNull().default(0),
globalItemId: integer("global_item_id").references(() => globalItems.id),
foundPriceCents: integer("found_price_cents"),
foundPriceCurrency: text("found_price_currency"),
foundPriceDate: timestamp("found_price_date"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
@@ -268,3 +273,43 @@ export const oauthTokens = pgTable("oauth_tokens", {
refreshExpiresAt: timestamp("refresh_expires_at").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// ── Market Prices ──────────────────────────────────────────────────
export const marketPrices = pgTable(
"market_prices",
{
id: serial("id").primaryKey(),
globalItemId: integer("global_item_id")
.notNull()
.references(() => globalItems.id, { onDelete: "cascade" }),
market: text("market").notNull(),
currency: text("currency").notNull(),
priceCents: integer("price_cents").notNull(),
source: text("source"),
createdAt: timestamp("created_at").defaultNow().notNull(),
},
(table) => [unique().on(table.globalItemId, table.market, table.currency)],
);
// ── Community Prices ───────────────────────────────────────────────
export const communityPrices = pgTable(
"community_prices",
{
id: serial("id").primaryKey(),
globalItemId: integer("global_item_id")
.notNull()
.references(() => globalItems.id, { onDelete: "cascade" }),
userId: integer("user_id")
.notNull()
.references(() => users.id),
market: text("market").notNull(),
currency: text("currency").notNull(),
priceCents: integer("price_cents").notNull(),
priceDate: timestamp("price_date"),
sourceType: text("source_type").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
},
(table) => [unique().on(table.globalItemId, table.userId, table.sourceType)],
);