import { BaseSchema } from '@adonisjs/lucid/schema' import env from '#start/env' /** * release_chunks' indexes with its chunks in CHUNK_TABLESPACE (the HDD), not the catalog's tablespace: a chunk is * read from the HDD anyway, and the October partition's three indexes took 2.9 GB of the NVMe (its pkey never * scanned; LOG.md 2026-10-14 (54)). The parent's partitioned indexes too, so new partitions put theirs there. * Homelab was moved by hand first; a no-op where they're there already. */ export default class extends BaseSchema { async up() { const tablespace = env.get('CHUNK_TABLESPACE') if (!tablespace) return this.defer(async (db) => { const { rows } = await db.rawQuery( `SELECT i.relname FROM pg_class c JOIN pg_index x ON x.indrelid = c.oid JOIN pg_class i ON i.oid = x.indexrelid LEFT JOIN pg_tablespace t ON t.oid = i.reltablespace WHERE c.relname LIKE 'release_chunks%' AND coalesce(t.spcname, 'pg_default') <> ?`, [tablespace] ) for (const { relname } of rows) await db.rawQuery(`ALTER INDEX ${relname} SET TABLESPACE ${tablespace}`) }) } async down() {} }