-- CreateTable CREATE TABLE "audit_exports" ( "id" TEXT NOT NULL, "organizationId" TEXT NOT NULL, "status" TEXT NOT NULL DEFAULT 'processing', "totalRows" INTEGER NOT NULL, "capRows" INTEGER NOT NULL, "rows" INTEGER NOT NULL DEFAULT 0, "truncated" BOOLEAN NOT NULL DEFAULT false, "filters" JSONB NOT NULL DEFAULT '{}', "error" TEXT, "downloadUrlAt" TIMESTAMP(3), "downloadUsed" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3) NOT NULL, "completedAt" TIMESTAMP(3), CONSTRAINT "audit_exports_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE INDEX "audit_exports_organizationId_status_idx" ON "audit_exports"("organizationId", "status"); -- CreateIndex CREATE INDEX "audit_exports_organizationId_createdAt_idx" ON "audit_exports"("organizationId", "createdAt"); -- AddForeignKey ALTER TABLE "audit_exports" ADD CONSTRAINT "audit_exports_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;