feat(maintenance): DB maintenance UI card + fix ruff I001
- Settings → Maintenance gains a "Database maintenance" card: a "Run VACUUM ANALYZE now" button (enqueues the maintenance task) plus a per-table bloat readout (live/dead/dead%/last vacuum) from /api/admin/maintenance/db-stats. - dbMaintenance store (loadStats / runVacuum) + test. - Fix ruff I001: combine the two _sync_engine imports onto one line. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { setActivePinia, createPinia } from 'pinia'
|
||||
import { useDbMaintenanceStore } from '../src/stores/dbMaintenance.js'
|
||||
|
||||
function stubFetch(handler) {
|
||||
globalThis.fetch = vi.fn(async (url, init) => {
|
||||
const { status, body } = handler(url, init)
|
||||
return {
|
||||
ok: status >= 200 && status < 300,
|
||||
status,
|
||||
statusText: String(status),
|
||||
text: async () => (body == null ? '' : JSON.stringify(body)),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('dbMaintenance store', () => {
|
||||
beforeEach(() => setActivePinia(createPinia()))
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
|
||||
it('loadStats populates the bloat table', async () => {
|
||||
const s = useDbMaintenanceStore()
|
||||
stubFetch(() => ({
|
||||
status: 200,
|
||||
body: { tables: [{ table: 'image_record', live: 5, dead: 1, dead_pct: 16.7, last_vacuum: null }] },
|
||||
}))
|
||||
await s.loadStats()
|
||||
expect(s.tables).toHaveLength(1)
|
||||
expect(s.tables[0].table).toBe('image_record')
|
||||
})
|
||||
|
||||
it('runVacuum POSTs the trigger endpoint', async () => {
|
||||
const s = useDbMaintenanceStore()
|
||||
const calls = []
|
||||
stubFetch((url, init) => {
|
||||
calls.push({ url, init })
|
||||
return { status: 202, body: { status: 'queued' } }
|
||||
})
|
||||
await s.runVacuum()
|
||||
const c = calls.at(-1)
|
||||
expect(c.url).toContain('/api/admin/maintenance/vacuum')
|
||||
expect(c.init.method).toBe('POST')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user