// Read-only diagnostic: introspect the temp DB created by `prisma migrate deploy` // to check whether the migrated schema matches schema.prisma (drift check). // Usage: node audit-results/tmp/inspect-db.cjs const path = require("node:path"); const Database = require("better-sqlite3"); const dbPath = process.argv[2]; if (!dbPath) { console.error("usage: node inspect-db.cjs "); process.exit(2); } const db = new Database(path.resolve(dbPath), { readonly: true }); const tables = db .prepare("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name") .all() .map((r) => r.name); console.log("=== TABLES ==="); console.log(tables.join(", ")); console.log("Has MaterialGroup table:", tables.includes("MaterialGroup")); for (const table of ["Deck", "QuizSet", "ShareLink", "MaterialGroup"]) { if (tables.includes(table)) { const cols = db .prepare(`PRAGMA table_info('${table}')`) .all() .map((r) => r.name); console.log(`--- ${table} columns ---`); console.log(cols.join(", ")); if (table === "Deck" || table === "QuizSet" || table === "ShareLink") { console.log(` -> has groupId:`, cols.includes("groupId")); } } else { console.log(`--- ${table}: MISSING TABLE ---`); } } const indexes = db .prepare("SELECT name, tbl_name FROM sqlite_master WHERE type='index' ORDER BY name") .all() .map((r) => `${r.tbl_name}.${r.name}`); console.log("=== INDEXES (count) ===", indexes.length); // Confirm migrations table const applied = db.prepare("SELECT migration_name FROM _prisma_migrations ORDER BY started_at").all(); console.log("=== APPLIED MIGRATIONS ==="); applied.forEach((m) => console.log(" -", m.migration_name)); db.close(); console.log("DONE");