diff --git a/postgres/004-set-type.sql b/postgres/004-set-type.sql new file mode 100644 index 0000000..dd235f9 --- /dev/null +++ b/postgres/004-set-type.sql @@ -0,0 +1,4 @@ +ALTER TABLE "sets" +ADD COLUMN IF NOT EXISTS "set_type" TEXT NOT NULL DEFAULT 'core'; + +CREATE INDEX IF NOT EXISTS "sets_type" ON "sets" ("set_type"); diff --git a/tutor/database.py b/tutor/database.py index 4b7e520..2d27165 100644 --- a/tutor/database.py +++ b/tutor/database.py @@ -335,14 +335,16 @@ async def store_price( ) -async def store_set(db: psycopg.AsyncCursor, set_code: str, name: str) -> None: +async def store_set( + db: psycopg.AsyncCursor, set_code: str, set_type: str, name: str +) -> None: await db.execute( """ - INSERT INTO "sets" ("set_code", "name") - VALUES (%(set_code)s, %(name)s) + INSERT INTO "sets" ("set_code", "set_type", "name") + VALUES (%(set_code)s, %(set_type)s, %(name)s) ON CONFLICT ("set_code") DO NOTHING """, - {"set_code": set_code, "name": name}, + {"set_code": set_code, "set_type": set_type, "name": name}, )