import { BaseSchema } from '@adonisjs/lucid/schema' /** * Lease lanes (REBUILD.md, "Voyager 3: window indexing", 1, amended 2026-10-27): a group has two cursors, each with * its own holder, window and snapshot. The `history` lane works the ranges the lease bounds hand out (the windows, * the history), the `tail` lane the tail planner's (priority at or below the tail's): a thread on the tail never * waits behind a group's history, and a held history group's tail isn't stuck behind its days of ranges. */ export default class extends BaseSchema { async up() { this.schema.raw( `ALTER TABLE group_leases ADD COLUMN lane varchar(8) NOT NULL DEFAULT 'history'` ) this.schema.raw(`ALTER TABLE group_leases DROP CONSTRAINT group_leases_pkey`) this.schema.raw(`ALTER TABLE group_leases ADD PRIMARY KEY (group_id, lane)`) // Counts the leases handed out: odd and even ones start from the other half of the order's mix. this.schema.raw(`CREATE SEQUENCE group_lease_turns`) } async down() { this.schema.raw(`DROP SEQUENCE IF EXISTS group_lease_turns`) this.schema.raw(`DELETE FROM group_leases WHERE lane <> 'history'`) this.schema.raw(`ALTER TABLE group_leases DROP CONSTRAINT group_leases_pkey`) this.schema.raw(`ALTER TABLE group_leases DROP COLUMN lane`) this.schema.raw(`ALTER TABLE group_leases ADD PRIMARY KEY (group_id)`) } }