Files
usenet-indexer/database/migrations/1770000003200_rarely_read_tables_with_chunks.ts
T
Daan MeijerandClaude Opus 5.5 c65282ec5d
Test and deploy / test (push) Successful in 54s
Test and deploy / edge (push) Successful in 1m48s
Test and deploy / deploy (push) Successful in 2m49s
par2_files, fragments and probe_cache with the chunks (CHUNK_TABLESPACE)
~20 GB of the NVMe, read by key only; the catalog was at its cap and history
paused. Moved on homelab by hand (3 min, writers stopped; the cap raised to
100); the migration does the same on a new deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 23:11:36 +02:00

33 lines
1.3 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
import env from '#start/env'
/**
* par2_files, fragments and probe_cache, with their indexes, in CHUNK_TABLESPACE (the HDD): ~20 GB of the NVMe at
* 42M releases, read by key only (the merger, the fragment merger, the prober). The catalog was at its
* CATALOG_MAX_NVME_GB cap and history paused (LOG.md 2026-10-14 (55)). Homelab was moved by hand first (3 min,
* with the writers stopped); a no-op where they're there already.
*/
const TABLES = ['par2_files', 'fragments', 'probe_cache']
export default class extends BaseSchema {
async up() {
const tablespace = env.get('CHUNK_TABLESPACE')
if (!tablespace) return
this.defer(async (db) => {
for (const table of TABLES) {
const { rows } = await db.rawQuery(
`SELECT c.relname, c.relkind FROM pg_class c LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
WHERE (c.relname = ? OR c.oid IN (SELECT indexrelid FROM pg_index WHERE indrelid = ?::regclass))
AND coalesce(t.spcname, 'pg_default') <> ?`,
[table, table, tablespace]
)
for (const { relname, relkind } of rows) {
await db.rawQuery(`ALTER ${relkind === 'i' ? 'INDEX' : 'TABLE'} ${relname} SET TABLESPACE ${tablespace}`)
}
}
})
}
async down() {}
}