1-- CreateTable 2CREATE TABLE "audit_exports" ( 3 "id" TEXT NOT NULL, 4 "organizationId" TEXT NOT NULL, 5 "status" TEXT NOT NULL DEFAULT 'processing', 6 "totalRows" INTEGER NOT NULL, 7 "capRows" INTEGER NOT NULL, 8 "rows" INTEGER NOT NULL DEFAULT 0, 9 "truncated" BOOLEAN NOT NULL DEFAULT false, 10 "filters" JSONB NOT NULL DEFAULT '{}', 11 "error" TEXT, 12 "downloadUrlAt" TIMESTAMP(3), 13 "downloadUsed" BOOLEAN NOT NULL DEFAULT false, 14 "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 15 "updatedAt" TIMESTAMP(3) NOT NULL, 16 "completedAt" TIMESTAMP(3), 17 18 CONSTRAINT "audit_exports_pkey" PRIMARY KEY ("id") 19); 20 21-- CreateIndex 22CREATE INDEX "audit_exports_organizationId_status_idx" ON "audit_exports"("organizationId", "status"); 23 24-- CreateIndex 25CREATE INDEX "audit_exports_organizationId_createdAt_idx" ON "audit_exports"("organizationId", "createdAt"); 26 27-- AddForeignKey 28ALTER TABLE "audit_exports" ADD CONSTRAINT "audit_exports_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE; 29