| 56 | } |
| 57 | |
| 58 | async function hasDrizzleMigrationHistory(path: string): Promise<boolean> { |
| 59 | if (!existsSync(path)) return true; |
| 60 | |
| 61 | const db = await PGlite.create(path); |
| 62 | const result = await db.query<{ exists: boolean }>(` |
| 63 | SELECT EXISTS ( |
| 64 | SELECT 1 |
| 65 | FROM information_schema.tables |
| 66 | WHERE table_schema = 'drizzle' |
| 67 | AND table_name = '__drizzle_migrations' |
| 68 | ) AS "exists" |
| 69 | `); |
| 70 | await db.close(); |
| 71 | return result.rows[0]?.exists === true; |
| 72 | } |
| 73 | |
| 74 | if (!(await hasDrizzleMigrationHistory(DB_PATH))) { |
| 75 | console.log("[dev-db] Resetting dev database without Drizzle migration history"); |