Add a materialized view tracking collection price history
This commit is contained in:
parent
ab66c92871
commit
69651f259d
2 changed files with 14 additions and 0 deletions
13
postgres/007-card-price-history-materialized-view.sql
Normal file
13
postgres/007-card-price-history-materialized-view.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
DROP MATERIALIZED VIEW IF EXISTS "collection_price_history";
|
||||||
|
CREATE MATERIALIZED VIEW "collection_price_history" AS
|
||||||
|
SELECT "card_prices"."date"::timestamp AS "date"
|
||||||
|
, SUM(CASE WHEN "copies"."isFoil"
|
||||||
|
THEN "card_prices"."usd_foil"
|
||||||
|
ELSE "card_prices"."usd"
|
||||||
|
END) AS "value"
|
||||||
|
FROM "cards"
|
||||||
|
JOIN "copies" USING ("scryfall_id")
|
||||||
|
JOIN "card_prices" USING ("scryfall_id")
|
||||||
|
WHERE "copies"."created_date" <= "card_prices"."date"::timestamp
|
||||||
|
GROUP BY "card_prices"."date"
|
||||||
|
ORDER BY "card_prices"."date";
|
|
@ -329,6 +329,7 @@ def update_scryfall(ctx, filename):
|
||||||
print("Refreshing materialized views")
|
print("Refreshing materialized views")
|
||||||
await cursor.execute('REFRESH MATERIALIZED VIEW "cards"')
|
await cursor.execute('REFRESH MATERIALIZED VIEW "cards"')
|
||||||
await cursor.execute('REFRESH MATERIALIZED VIEW "oracle_latest"')
|
await cursor.execute('REFRESH MATERIALIZED VIEW "oracle_latest"')
|
||||||
|
await cursor.execute('REFRESH MATERIALIZED VIEW "collection_price_history"')
|
||||||
|
|
||||||
await tutor.database.store_var(cursor, "last_update", str(today))
|
await tutor.database.store_var(cursor, "last_update", str(today))
|
||||||
await conn.commit()
|
await conn.commit()
|
||||||
|
|
Loading…
Reference in a new issue