ui changes and cs prices
All checks were successful
Test and deploy staging / staging (push) Successful in 11m52s
All checks were successful
Test and deploy staging / staging (push) Successful in 11m52s
This commit is contained in:
81
src/lib/server/db/schema/cs-prices.ts
Normal file
81
src/lib/server/db/schema/cs-prices.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { index, integer, pgTable, text, timestamp, uniqueIndex, bigint } from 'drizzle-orm/pg-core';
|
||||
import { id } from './helpers';
|
||||
|
||||
// A Steam market hash name identifies a listing, including wear and special variants.
|
||||
export const csMarketItems = pgTable(
|
||||
'cs_market_items',
|
||||
{
|
||||
id: id(),
|
||||
marketHashName: text('market_hash_name').notNull(),
|
||||
name: text('name').notNull(),
|
||||
iconUrl: text('icon_url'),
|
||||
itemType: text('item_type'),
|
||||
firstSeenAt: timestamp('first_seen_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
lastSeenAt: timestamp('last_seen_at', { withTimezone: true }).notNull().defaultNow()
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('cs_market_items_hash_idx').on(table.marketHashName),
|
||||
index('cs_market_items_name_idx').on(table.name)
|
||||
]
|
||||
);
|
||||
|
||||
// Keep source observations intact. Aggregation happens only when the chart is requested.
|
||||
export const csPriceObservations = pgTable(
|
||||
'cs_price_observations',
|
||||
{
|
||||
id: bigint('id', { mode: 'number' }).primaryKey().generatedAlwaysAsIdentity(),
|
||||
itemId: integer('item_id')
|
||||
.notNull()
|
||||
.references(() => csMarketItems.id, { onDelete: 'cascade' }),
|
||||
source: text('source').notNull(),
|
||||
currency: text('currency').notNull(),
|
||||
observedAt: timestamp('observed_at', { withTimezone: true }).notNull(),
|
||||
priceCents: integer('price_cents').notNull(),
|
||||
volume: integer('volume'),
|
||||
kind: text('kind').notNull(),
|
||||
importedAt: timestamp('imported_at', { withTimezone: true }).notNull().defaultNow()
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('cs_price_observations_unique_idx').on(
|
||||
table.itemId,
|
||||
table.source,
|
||||
table.currency,
|
||||
table.observedAt,
|
||||
table.kind
|
||||
),
|
||||
index('cs_price_observations_lookup_idx').on(
|
||||
table.itemId,
|
||||
table.source,
|
||||
table.currency,
|
||||
table.observedAt
|
||||
),
|
||||
index('cs_price_observations_time_idx').on(table.observedAt)
|
||||
]
|
||||
);
|
||||
|
||||
export const csItemDimensions = pgTable(
|
||||
'cs_item_dimensions',
|
||||
{
|
||||
itemId: integer('item_id')
|
||||
.notNull()
|
||||
.references(() => csMarketItems.id, { onDelete: 'cascade' }),
|
||||
key: text('key').notNull(),
|
||||
value: text('value').notNull()
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('cs_item_dimensions_unique_idx').on(table.itemId, table.key),
|
||||
index('cs_item_dimensions_filter_idx').on(table.key, table.value, table.itemId)
|
||||
]
|
||||
);
|
||||
|
||||
export const csPriceStreams = pgTable(
|
||||
'cs_price_streams',
|
||||
{
|
||||
source: text('source').notNull(),
|
||||
currency: text('currency').notNull(),
|
||||
kind: text('kind').notNull()
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('cs_price_streams_unique_idx').on(table.source, table.currency, table.kind)
|
||||
]
|
||||
);
|
||||
@@ -8,3 +8,4 @@ export * from './game-tracker';
|
||||
export * from './animaldex';
|
||||
export * from './lists';
|
||||
export * from './money-tracker';
|
||||
export * from './cs-prices';
|
||||
|
||||
Reference in New Issue
Block a user