import { BaseSchema } from '@adonisjs/lucid/schema' /** * probe_candidates, with its indexes, in the catalog's tablespace (default_tablespace: nvme on homelab), out of * CHUNK_TABLESPACE where migration 6000 put it: the prober's catalog claim updates it from random points every * minute, and on the HDD, beside the pending ladder's sweep and autovacuum, a claim took 2–3 minutes with all the * lanes waiting (LOG.md 2026-11-03 (136)). Homelab moved it by hand (edge, node-api and the workers stopped; ~8 GB); * 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 = 'probe_candidates' OR c.oid IN (SELECT indexrelid FROM pg_index WHERE indrelid = 'probe_candidates'::regclass)) AND c.relkind IN ('r', 'i') AND coalesce(t.spcname, 'pg_default') <> ? ORDER BY c.relkind DESC, c.relname`, [target] ) for (const { relname, relkind } of rows) { await db.rawQuery( `ALTER ${relkind === 'i' ? 'INDEX' : 'TABLE'} ${relname} SET TABLESPACE ${target}` ) } }) } async down() {} }