import { BaseSchema } from '@adonisjs/lucid/schema' /** * Unmatched spots are matched again in turns (`rematched_at`), for 30 days after their inspection, also once they * became a release of their own: the header pass may build their releases later (a spot's history before the * catalog's), and then the spot moves to that release (LOG.md 2026-10-13 (45)). */ export default class extends BaseSchema { async up() { this.schema.raw(`ALTER TABLE spots ADD COLUMN IF NOT EXISTS rematched_at timestamptz`) // Inspected before the inspector set it (2026-10-13). this.schema.raw(`UPDATE spots SET matched = 0 WHERE status = 'inspected' AND matched IS NULL`) this.schema.raw(`DROP INDEX IF EXISTS spots_unmatched_idx`) this.schema.raw(`CREATE INDEX IF NOT EXISTS spots_unmatched_idx ON spots (coalesce(rematched_at, inspected_at)) WHERE status = 'inspected' AND matched = 0`) } async down() { this.schema.raw(`DROP INDEX IF EXISTS spots_unmatched_idx`) this.schema.raw(`ALTER TABLE spots DROP COLUMN IF EXISTS rematched_at`) } }