-- CreateEnum CREATE TYPE "EventStatus" AS ENUM ('pending', 'processing', 'done', 'partial', 'failed'); -- CreateTable CREATE TABLE "webhook_events" ( "id" TEXT NOT NULL, "business_object" TEXT NOT NULL, "operation" TEXT NOT NULL, "subject" TEXT NOT NULL, "payload" JSONB NOT NULL, "received_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "status" "EventStatus" NOT NULL DEFAULT 'pending', CONSTRAINT "webhook_events_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "replication_attempts" ( "id" SERIAL NOT NULL, "event_id" TEXT NOT NULL, "subsidiary" TEXT NOT NULL, "verb_used" TEXT NOT NULL, "http_status" INTEGER, "error_message" TEXT, "attempted_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "replication_attempts_pkey" PRIMARY KEY ("id") ); -- AddForeignKey ALTER TABLE "replication_attempts" ADD CONSTRAINT "replication_attempts_event_id_fkey" FOREIGN KEY ("event_id") REFERENCES "webhook_events"("id") ON DELETE RESTRICT ON UPDATE CASCADE;