Source: config/migrations/20260802-eventlog-cursor.js

export const id = '20260802-eventlog-cursor';
export const name = 'Add monotonic seq cursor column to eventLog for replay contract';

/**
 * The cross-service contract (080-Workspaces/018-Cross-Service-Contracts.mdx)
 * requires replay via an opaque, strictly ordered cursor. The existing eventLog
 * PK is (Timestamp, EventKey), which is not a reliable monotonic cursor. A
 * BIGINT AUTO_INCREMENT seq column provides the stable ordering needed by the
 * GET /api/kpe20/events replay endpoint.
 */
export const migrate = async ({ query }) => {
    await query(`
        ALTER TABLE eventLog
        ADD COLUMN seq BIGINT NOT NULL AUTO_INCREMENT UNIQUE
    `, []);
};