ci/woodpecker/pr/web-db Pipeline was successful
ci/woodpecker/pr/web-pieces Pipeline was successful
ci/woodpecker/pr/web-worker Pipeline was successful
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/push/web-db Pipeline was successful
ci/woodpecker/push/web-pieces Pipeline was successful
ci/woodpecker/push/web-worker Pipeline was successful
ci/woodpecker/push/web Pipeline was successful
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import { writeFile } from 'node:fs/promises'
|
|
import { getDatabaseClient, migrate, sql } from '@luzzle/core'
|
|
import { runWebMigrations } from '@luzzle/web.db'
|
|
|
|
const db = getDatabaseClient(':memory:')
|
|
|
|
try {
|
|
const coreResult = await migrate(db)
|
|
if (coreResult.error) throw coreResult.error
|
|
|
|
const webResult = await runWebMigrations(db)
|
|
if (webResult.error) throw webResult.error
|
|
|
|
const schema = await sql`
|
|
SELECT sql FROM sqlite_schema
|
|
WHERE sql IS NOT NULL
|
|
AND name NOT LIKE 'sqlite_%'
|
|
AND name NOT LIKE 'kysely_%'
|
|
AND name NOT IN (
|
|
SELECT name FROM pragma_table_list WHERE type = 'shadow'
|
|
)
|
|
ORDER BY CASE type
|
|
WHEN 'table' THEN 0
|
|
WHEN 'index' THEN 1
|
|
ELSE 2
|
|
END, name
|
|
`.execute(db)
|
|
|
|
const statements = schema.rows.map(row => `${row.sql};`)
|
|
const snapshot = [
|
|
'-- Generated by pnpm --filter @luzzle/web.db schema:generate. Do not edit.',
|
|
'-- Statement boundaries let the test helper load complete triggers without parsing SQL.',
|
|
'',
|
|
statements.join('\n\n-- statement-breakpoint\n\n'),
|
|
'',
|
|
].join('\n')
|
|
|
|
await writeFile(new URL('../../worker/test/db.sql', import.meta.url), snapshot)
|
|
console.log(`Generated worker/test/db.sql (${statements.length} schema objects)`)
|
|
} finally {
|
|
await db.destroy()
|
|
}
|