mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-11 20:05:25 +00:00
add seed script
This commit is contained in:
parent
c304e344c4
commit
102fa63d58
2 changed files with 74 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import { migrateDuplicateConnections } from "./scripts/migrate-duplicate-connect
|
|||
import { injectAuditData } from "./scripts/inject-audit-data";
|
||||
import { confirmAction } from "./utils";
|
||||
import { createLogger } from "@sourcebot/logger";
|
||||
import { seed } from "./scripts/seed";
|
||||
|
||||
export interface Script {
|
||||
run: (prisma: PrismaClient) => Promise<void>;
|
||||
|
|
@ -12,6 +13,7 @@ export interface Script {
|
|||
export const scripts: Record<string, Script> = {
|
||||
"migrate-duplicate-connections": migrateDuplicateConnections,
|
||||
"inject-audit-data": injectAuditData,
|
||||
"seed": seed,
|
||||
}
|
||||
|
||||
const parser = new ArgumentParser();
|
||||
|
|
|
|||
72
packages/db/tools/scripts/seed.ts
Normal file
72
packages/db/tools/scripts/seed.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { ConnectionSyncStatus, Prisma, PrismaClient, RepoIndexingStatus } from "@prisma/client";
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Script } from "../scriptRunner";
|
||||
|
||||
const TEST_ORG_ID = 1;
|
||||
const TEST_CONNECTION_ID = 1;
|
||||
|
||||
export const seed: Script = {
|
||||
run: async (prisma: PrismaClient) => {
|
||||
|
||||
const org = await prisma.org.findUnique({
|
||||
where: {
|
||||
id: TEST_ORG_ID,
|
||||
}
|
||||
});
|
||||
|
||||
if (!org) {
|
||||
await prisma.org.create({
|
||||
data: {
|
||||
id: TEST_ORG_ID,
|
||||
name: 'Test Org',
|
||||
domain: 'test-org.com',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const connection = await prisma.connection.findUnique({
|
||||
where: {
|
||||
id: TEST_CONNECTION_ID,
|
||||
}
|
||||
});
|
||||
|
||||
if (!connection) {
|
||||
await prisma.connection.create({
|
||||
data: {
|
||||
id: TEST_CONNECTION_ID,
|
||||
name: 'Test Connection',
|
||||
orgId: TEST_ORG_ID,
|
||||
syncedAt: new Date(),
|
||||
syncStatus: ConnectionSyncStatus.SYNCED,
|
||||
config: {} as unknown as Prisma.InputJsonValue,
|
||||
connectionType: 'github',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < 20000; i++) {
|
||||
const name = uuidv4();
|
||||
await prisma.repo.create({
|
||||
data: {
|
||||
name: name,
|
||||
orgId: TEST_ORG_ID,
|
||||
external_id: name,
|
||||
external_codeHostType: 'github',
|
||||
external_codeHostUrl: 'https://github.com',
|
||||
repoIndexingStatus: RepoIndexingStatus.INDEXED,
|
||||
isFork: false,
|
||||
isArchived: false,
|
||||
indexedAt: new Date(),
|
||||
metadata: {},
|
||||
cloneUrl: 'https://github.com/sourcebot-dev/sourcebot-does-not-exist.git',
|
||||
connections: {
|
||||
create: {
|
||||
addedAt: new Date(),
|
||||
connectionId: TEST_CONNECTION_ID,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue