Compare commits

..

No commits in common. "0adb79c87142f9dfb2d0a29a4dfa699c734666e2" and "4aa4d3b53337c5d691ff0c2c9cae37340ef278eb" have entirely different histories.

5 changed files with 37 additions and 73 deletions

View file

@ -29,22 +29,7 @@ DO $$ BEGIN
END IF;
END $$;
CREATE TABLE IF NOT EXISTS "oracle" (
"oracle_id" UUID PRIMARY KEY,
"name" TEXT NOT NULL,
"color_identity" TEXT NOT NULL,
"cmc" DECIMAL(10, 2) NOT NULL,
"type_line" TEXT NOT NULL,
"edhrec_rank" INTEGER,
"oracle_text" TEXT,
"games" TEXT[] DEFAULT ARRAY[]::TEXT[],
"legalities" TEXT[] DEFAULT ARRAY[]::TEXT[]
);
CREATE INDEX IF NOT EXISTS "oracle_name" ON "oracle" ("name" COLLATE en_us_ci);
CREATE INDEX IF NOT EXISTS "oracle_color_identity" ON "oracle" ("color_identity");
CREATE TABLE IF NOT EXISTS "scryfall" (
CREATE TABLE IF NOT EXISTS "cards" (
"scryfall_id" UUID PRIMARY KEY,
"oracle_id" UUID,
"name" TEXT NOT NULL,
@ -65,10 +50,10 @@ CREATE TABLE IF NOT EXISTS "scryfall" (
FOREIGN KEY ("set_code") REFERENCES "sets" ("set_code")
);
CREATE INDEX IF NOT EXISTS "cards_name" ON "scryfall" ("name" COLLATE en_us_ci);
CREATE INDEX IF NOT EXISTS "cards_rarity" ON "scryfall" ("rarity");
CREATE INDEX IF NOT EXISTS "cards_color_identity" ON "scryfall" ("color_identity");
CREATE INDEX IF NOT EXISTS "cards_oracle_id" ON "scryfall" ("oracle_id");
CREATE INDEX IF NOT EXISTS "cards_name" ON "cards" ("name" COLLATE en_us_ci);
CREATE INDEX IF NOT EXISTS "cards_rarity" ON "cards" ("rarity");
CREATE INDEX IF NOT EXISTS "cards_color_identity" ON "cards" ("color_identity");
CREATE INDEX IF NOT EXISTS "cards_oracle_id" ON "cards" ("oracle_id");
CREATE TABLE IF NOT EXISTS "copies" (
"id" BIGSERIAL PRIMARY KEY,
@ -77,7 +62,7 @@ CREATE TABLE IF NOT EXISTS "copies" (
"isFoil" BOOLEAN NOT NULL DEFAULT FALSE,
"language" TEXT,
"condition" TEXT,
FOREIGN KEY ("scryfall_id") REFERENCES "scryfall" ("scryfall_id") ON DELETE CASCADE
FOREIGN KEY ("scryfall_id") REFERENCES "cards" ("scryfall_id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "card_prices" (
@ -89,7 +74,7 @@ CREATE TABLE IF NOT EXISTS "card_prices" (
"eur_foil" DECIMAL(10, 2),
"tix" DECIMAL(10, 2),
PRIMARY KEY ("scryfall_id", "date"),
FOREIGN KEY ("scryfall_id") REFERENCES "scryfall" ("scryfall_id") ON DELETE CASCADE
FOREIGN KEY ("scryfall_id") REFERENCES "cards" ("scryfall_id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "legalities" (
@ -97,7 +82,7 @@ CREATE TABLE IF NOT EXISTS "legalities" (
"format" TEXT NOT NULL,
"legality" TEXT NOT NULL,
PRIMARY KEY ("scryfall_id", "format"),
FOREIGN KEY ("scryfall_id") REFERENCES "scryfall" ("scryfall_id")
FOREIGN KEY ("scryfall_id") REFERENCES "cards" ("scryfall_id")
);
DO $$ BEGIN
@ -114,7 +99,7 @@ CREATE TABLE IF NOT EXISTS "games" (
"scryfall_id" UUID NOT NULL,
"game" game NOT NULL,
PRIMARY KEY ("scryfall_id", "game"),
FOREIGN KEY ("scryfall_id") REFERENCES "scryfall" ("scryfall_id")
FOREIGN KEY ("scryfall_id") REFERENCES "cards" ("scryfall_id")
);
CREATE TABLE IF NOT EXISTS "decks" (
@ -135,26 +120,10 @@ CREATE TABLE IF NOT EXISTS "deck_cards" (
"scryfall_id" UUID NOT NULL,
PRIMARY KEY ("deck_id", "scryfall_id"),
FOREIGN KEY ("deck_id") REFERENCES "decks" ("deck_id") ON DELETE CASCADE,
FOREIGN KEY ("scryfall_id") REFERENCES "scryfall" ("scryfall_id")
FOREIGN KEY ("scryfall_id") REFERENCES "cards" ("scryfall_id")
);
CREATE TABLE IF NOT EXISTS "vars" (
"key" TEXT PRIMARY KEY,
"value" TEXT
);
CREATE OR REPLACE VIEW "cards" AS
SELECT "oracle"."oracle_id"
, "oracle"."name"
, "oracle"."color_identity"
, "oracle"."cmc"
, "oracle"."type_line"
, "oracle"."edhrec_rank"
, "oracle"."oracle_text"
, "scryfall"."scryfall_id"
, "scryfall"."set_code"
, "scryfall"."collector_number"
, "scryfall"."rarity"
, "scryfall"."release_date"
FROM "oracle"
JOIN "scryfall" USING ("oracle_id");

View file

@ -252,28 +252,7 @@ def update_scryfall(ctx, filename):
print("Updating card data & indexes")
await cursor.execute(
"""
INSERT INTO "oracle"
SELECT DISTINCT "oracle_id"
, "name"
, "color_identity"
, "cmc"
, "type_line"
, "edhrec_rank"
, "oracle_text"
FROM "tmp_cards"
ON CONFLICT (oracle_id) DO UPDATE
SET "oracle_id" = "excluded"."oracle_id"
, "name" = "excluded"."name"
, "color_identity" = "excluded"."color_identity"
, "cmc" = "excluded"."cmc"
, "type_line" = "excluded"."type_line"
, "edhrec_rank" = "excluded"."edhrec_rank"
, "oracle_text" = "excluded"."oracle_text"
"""
)
await cursor.execute(
"""
INSERT INTO "scryfall" SELECT * FROM "tmp_cards"
INSERT INTO "cards" SELECT * FROM "tmp_cards"
ON CONFLICT (scryfall_id) DO UPDATE
SET "oracle_id" = "excluded"."oracle_id"
, "name" = "excluded"."name"

3
www/.gitignore vendored
View file

@ -1,3 +1,4 @@
bin
elm-stuff
node_modules
package-lock.json
public/elm.js

View file

@ -4,28 +4,30 @@ TARGET=public/elm.js
SOURCE=src/App.elm
ELM_FILES = $(shell find src -type f -name '*.elm')
ELM = ./bin/elm
NODE_BIN = ./node_modules/.bin
ELM = $(NODE_BIN)/elm
ELM_LIVE = $(NODE_BIN)/elm-live
ELMMAKE_FLAGS =
ifeq ($(DEBUG),1)
ELMMAKE_FLAGS += --debug
endif
all: $(TARGET)
all: node-deps $(TARGET)
$(ELM):
mkdir -p ./bin
curl -sL https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz \
| gunzip > $@
chmod +x $@
node-deps:
npm i
$(TARGET): $(ELM_FILES) $(ELM)
$(TARGET): $(ELM_FILES)
$(ELM) make $(ELMMAKE_FLAGS) $(SOURCE) --output $@
clean-deps:
rm -rf bin
rm -rf elm-stuff
rm -rf node_modules
clean:
rm -f $(TARGET)
rm -rf elm-stuff/build-artifacts
run: all
PATH="$(NODE_BIN):$$PATH" $(ELM_LIVE) $(SOURCE) --dir public --open -- $(ELMMAKE_FLAGS) --output $(TARGET)

13
www/package.json Normal file
View file

@ -0,0 +1,13 @@
{
"name": "tutor",
"description": "Tutor",
"version": "1.0.0",
"author": "Correl Roush <correl@gmail.com>",
"license": "MIT",
"devDependencies": {
"elm": "0.19.1"
},
"dependencies": {
"elm-live": "^4.0.2"
}
}