import { BaseSchema } from '@adonisjs/lucid/schema' /** * Group leases (REBUILD.md, "Voyager 3: window indexing", 1 and 5; 2026-10-26): a worker thread holds a group, not * a range, and indexes its ranges in article order through one carried window. One row a group: the holder and * its heartbeat, the range it works, and the snapshot of its window (the article it stands at: the next one to * index) that the coordinator keeps on bulk. Ranges stay what is planned, fetched and finished. */ export default class extends BaseSchema { async up() { this.schema.raw(` CREATE TABLE group_leases ( group_id integer PRIMARY KEY REFERENCES groups (id) ON DELETE CASCADE, -- The holder; null between holders. A holder quiet for LEASE_TTL_SECONDS is taken over. node_id integer, leased_at timestamptz, heartbeat_at timestamptz, -- The range the holder works (null between ranges). range_id bigint, -- The window's snapshot: the article it stands at (a resume point), and when it was taken; null: none. snapshot_next bigint, snapshot_at timestamptz, ranges_done integer NOT NULL DEFAULT 0, headers bigint NOT NULL DEFAULT 0, created_at timestamptz NOT NULL DEFAULT now() )`) this.schema.raw(`CREATE INDEX group_leases_held_idx ON group_leases (heartbeat_at) WHERE node_id IS NOT NULL`) } async down() { this.schema.raw(`DROP TABLE IF EXISTS group_leases`) } }