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.
34 lines
727 B
TypeScript
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");
|