Files
OpenPipe-llm/app/src/server/scripts/backfillApiKeys.ts
Kyle Corbitt 16aa6672fc Rename Organization to Project
We'll probably need a concept of organizations at some point in the future, but in practice the way we're using these in the codebase right now is as a project, so this renames it to that to avoid confusion.
2023-08-09 16:01:13 -07:00

34 lines
727 B
TypeScript

import { type Prisma } from "@prisma/client";
import { prisma } from "~/server/db";
import { generateApiKey } from "~/server/utils/generateApiKey";
console.log("backfilling api keys");
const projects = await prisma.project.findMany({
include: {
apiKeys: true,
},
});
console.log(`found ${projects.length} projects`);
const apiKeysToCreate: Prisma.ApiKeyCreateManyInput[] = [];
for (const proj of projects) {
if (!proj.apiKeys.length) {
apiKeysToCreate.push({
name: "Default API Key",
projectId: proj.id,
apiKey: generateApiKey(),
});
}
}
console.log(`creating ${apiKeysToCreate.length} api keys`);
await prisma.apiKey.createMany({
data: apiKeysToCreate,
});
console.log("done");