From 9d1a82bdf028a0d0c789e12555af5d88264df0ae Mon Sep 17 00:00:00 2001 From: lila Date: Tue, 31 Mar 2026 16:48:40 +0200 Subject: [PATCH] reviewing and updating deck generation --- documentation/roadmap.md | 2 +- .../wordlists/top1000englishnouns-unmatched | 34 ------------------- packages/db/src/db/schema.ts | 18 +++++----- ...reate-test-deck.ts => generating-decks.ts} | 2 +- packages/db/src/test-db-connection.ts | 5 --- 5 files changed, 10 insertions(+), 51 deletions(-) delete mode 100644 packages/db/src/data/wordlists/top1000englishnouns-unmatched rename packages/db/src/{create-test-deck.ts => generating-decks.ts} (97%) delete mode 100644 packages/db/src/test-db-connection.ts diff --git a/documentation/roadmap.md b/documentation/roadmap.md index 314e0e3..24c71ae 100644 --- a/documentation/roadmap.md +++ b/documentation/roadmap.md @@ -29,7 +29,7 @@ Done when: `GET /api/decks/1/terms?limit=10` returns 10 terms from a specific de [x] Write Drizzle schema: `terms`, `translations`, `language_pairs`, `term_glosses`, `decks`, `deck_terms` [x] Write and run migration (includes CHECK constraints for `pos`, `gloss_type`) [x] Write `packages/db/src/seed.ts` (imports ALL terms + translations, NO decks) -[ ] Download CEFR A1/A2 noun lists (from GitHub repos) +[x] Download CEFR A1/A2 noun lists (from GitHub repos) [ ] Write `scripts/build_decks.ts` (reads external CEFR lists, matches to DB, creates decks) [ ] Run `pnpm db:seed` → populates terms [ ] Run `pnpm db:build-decks` → creates curated decks diff --git a/packages/db/src/data/wordlists/top1000englishnouns-unmatched b/packages/db/src/data/wordlists/top1000englishnouns-unmatched deleted file mode 100644 index 08c21b2..0000000 --- a/packages/db/src/data/wordlists/top1000englishnouns-unmatched +++ /dev/null @@ -1,34 +0,0 @@ -a -other -us -may -st -paul -new -software -oxford -english -mary -japan -while -pp -membership -manchester -tony -alan -jones -un -northern -simon -behalf -co -graham -joe -guy -lewis -jane -taylor -co-operation -travel -self -thatcher \ No newline at end of file diff --git a/packages/db/src/db/schema.ts b/packages/db/src/db/schema.ts index 05848e5..89dfee9 100644 --- a/packages/db/src/db/schema.ts +++ b/packages/db/src/db/schema.ts @@ -7,7 +7,6 @@ import { unique, check, boolean, - integer, primaryKey, index, } from "drizzle-orm/pg-core"; @@ -133,19 +132,19 @@ export const decks = pgTable( id: uuid().primaryKey().defaultRandom(), name: text().notNull(), description: text(), - language_pair_id: uuid() + validated_for_languages: varchar({ length: 10 }) + .array() .notNull() - .references(() => language_pairs.id, { onDelete: "cascade" }), - created_by: uuid() - .notNull() - .references(() => users.id, { onDelete: "cascade" }), + .default([]), is_public: boolean().default(false).notNull(), created_at: timestamp({ withTimezone: true }).defaultNow().notNull(), }, (table) => [ - unique("unique_deck_name").on(table.name, table.created_by), - index("idx_decks_created_by").on(table.created_by), - index("idx_decks_language_pair").on(table.language_pair_id), + check( + "validated_languages_check", + sql`validated_for_languages <@ ARRAY[${sql.raw(SUPPORTED_LANGUAGE_CODES.map((l) => `'${l}'`).join(", "))}]::varchar[]`, + ), + unique("unique_deck_name").on(table.name), ], ); @@ -158,7 +157,6 @@ export const deck_terms = pgTable( term_id: uuid() .notNull() .references(() => terms.id, { onDelete: "cascade" }), - position: integer().notNull(), added_at: timestamp({ withTimezone: true }).defaultNow().notNull(), }, (table) => [ diff --git a/packages/db/src/create-test-deck.ts b/packages/db/src/generating-decks.ts similarity index 97% rename from packages/db/src/create-test-deck.ts rename to packages/db/src/generating-decks.ts index 985e0b9..9a15bab 100644 --- a/packages/db/src/create-test-deck.ts +++ b/packages/db/src/generating-decks.ts @@ -16,7 +16,7 @@ Close the DB connection import fs from "node:fs/promises"; import { db } from "@glossa/db"; import { translations } from "@glossa/db/schema"; -import { inArray, and, eq } from "drizzle-orm"; +import { inArray } from "drizzle-orm"; const wordlistPath = "./src/data/wordlists/top1000englishnouns"; diff --git a/packages/db/src/test-db-connection.ts b/packages/db/src/test-db-connection.ts deleted file mode 100644 index abcc087..0000000 --- a/packages/db/src/test-db-connection.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { db } from "./index.js"; - -const result = await db.execute("select 1"); - -console.log("result: ", result);