ALTER TABLE "workflow_run_modules" ADD COLUMN IF NOT EXISTS "idempotency_key" text;
ALTER TABLE "workflow_run_modules" ADD COLUMN IF NOT EXISTS "retry_count" integer DEFAULT 0 NOT NULL;
ALTER TABLE "workflow_run_modules" ADD COLUMN IF NOT EXISTS "max_retries" integer DEFAULT 2 NOT NULL;

CREATE TABLE IF NOT EXISTS "workflow_approvals" (
  "id" text PRIMARY KEY DEFAULT gen_random_uuid()::text NOT NULL,
  "run_id" text NOT NULL REFERENCES "workflow_runs"("id") ON DELETE cascade,
  "approval_id" text NOT NULL,
  "status" text DEFAULT 'pending' NOT NULL,
  "payload" jsonb,
  "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  "resolved_at" timestamp with time zone
);
CREATE INDEX IF NOT EXISTS "workflow_approvals_run_idx" ON "workflow_approvals" ("run_id", "approval_id");
