diff --git a/database/migrations/1770000003700_par2_files_back_on_nvme.ts b/database/migrations/1770000003700_par2_files_back_on_nvme.ts new file mode 100644 index 0000000..58fa891 --- /dev/null +++ b/database/migrations/1770000003700_par2_files_back_on_nvme.ts @@ -0,0 +1,29 @@ +import { BaseSchema } from '@adonisjs/lucid/schema' + +/** + * par2_files, with its indexes, back in the catalog's tablespace (default_tablespace: nvme on homelab), out of + * CHUNK_TABLESPACE where 3200 put it: the merger matches every new file hash against it and reads each set's rows, a + * random read per row on the HDD (~1,090 sets/min, a full round ~28 h; LOG.md 2026-10-15 (58)). Homelab rebuilt it + * there by hand without the complete and judged sets' rows (app/services/par2_pruner.ts; LOG.md 2026-10-16 (60)); a + * no-op where it's there already, or without a default tablespace (tests). + */ +export default class extends BaseSchema { + async up() { + this.defer(async (db) => { + const { rows: setting } = await db.rawQuery(`SELECT current_setting('default_tablespace') AS target`) + const target = setting[0].target + if (!target) return + 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 = 'par2_files' OR c.oid IN (SELECT indexrelid FROM pg_index WHERE indrelid = 'par2_files'::regclass)) + AND coalesce(t.spcname, 'pg_default') <> ?`, + [target] + ) + for (const { relname, relkind } of rows) { + await db.rawQuery(`ALTER ${relkind === 'i' ? 'INDEX' : 'TABLE'} ${relname} SET TABLESPACE ${target}`) + } + }) + } + + async down() {} +}