Files
vps-tracker/packages/db/src/runtime-migrate.test.ts
T
DenozordecandCursor 2931d6ee0f
Docker / build (push) Failing after 18s
fix(db): bootstrap полной схемы на чистой установке и логи Docker
Пустой volume больше не отдаёт 500 на /api/data из-за отсутствующих таблиц. В compose добавлены json-file логи с ротацией и LOG_LEVEL для Fastify.

Co-authored-by: Cursor <[email protected]>
2026-07-19 04:27:42 +07:00

45 lines
1.4 KiB
TypeScript

import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { closeDb, getDb, getSqlite } from './index.js'
import { resetRuntimeMigrate } from './runtime-migrate.js'
import { getSnapshot } from './repositories/snapshot.js'
import { runWithSpace, MAIN_SPACE_ID } from './space-context.js'
describe('ensureRuntimeSchema (empty DB)', () => {
let dir: string
afterEach(() => {
closeDb()
resetRuntimeMigrate()
delete process.env.DB_PATH
if (dir) rmSync(dir, { recursive: true, force: true })
})
it('bootstraps core tables and serves empty snapshot', () => {
dir = mkdtempSync(join(tmpdir(), 'vps-tracker-db-'))
process.env.DB_PATH = join(dir, 'fresh.db')
resetRuntimeMigrate()
closeDb()
getDb()
const tables = getSqlite()
.prepare(
`SELECT name FROM sqlite_master WHERE type='table' AND name IN ('vps','settings','providers','spaces')`,
)
.all() as { name: string }[]
expect(tables.map((t) => t.name).sort()).toEqual([
'providers',
'settings',
'spaces',
'vps',
])
const snap = runWithSpace(MAIN_SPACE_ID, () => getSnapshot())
expect(snap.spaceId).toBe(MAIN_SPACE_ID)
expect(snap.vps).toEqual([])
expect(snap.settings.length).toBeGreaterThanOrEqual(1)
})
})