ALTER TABLE IF EXISTS gateway_tasks
  ADD COLUMN IF NOT EXISTS async_mode boolean NOT NULL DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_gateway_tasks_async_queue
  ON gateway_tasks(async_mode, status, next_run_at, priority, created_at)
  WHERE async_mode = true;
