BEGIN;

CREATE TABLE IF NOT EXISTS run_leases (
    run_id TEXT PRIMARY KEY REFERENCES strategy_run(run_id) ON DELETE CASCADE,
    owner_id TEXT NOT NULL,
    leased_at TIMESTAMPTZ NOT NULL,
    expires_at TIMESTAMPTZ NOT NULL,
    heartbeat_at TIMESTAMPTZ
);

CREATE INDEX IF NOT EXISTS idx_run_leases_owner_expires
    ON run_leases (owner_id, expires_at DESC);

COMMIT;
