1+ import { Script } from "../scriptRunner" ;
2+ import { PrismaClient } from "../../dist" ;
3+ import { createLogger } from "@sourcebot/logger" ;
4+
5+ const logger = createLogger ( 'inject-repo-data' ) ;
6+
7+ const NUM_REPOS = 100000 ;
8+
9+ export const injectRepoData : Script = {
10+ run : async ( prisma : PrismaClient ) => {
11+ const orgId = 1 ;
12+
13+ // Check if org exists
14+ const org = await prisma . org . findUnique ( {
15+ where : { id : orgId }
16+ } ) ;
17+
18+ if ( ! org ) {
19+ await prisma . org . create ( {
20+ data : {
21+ id : orgId ,
22+ name : 'Test Org' ,
23+ domain : 'test-org.com'
24+ }
25+ } ) ;
26+ }
27+
28+ const connection = await prisma . connection . create ( {
29+ data : {
30+ orgId,
31+ name : 'test-connection' ,
32+ connectionType : 'github' ,
33+ config : { }
34+ }
35+ } ) ;
36+
37+
38+ logger . info ( `Creating ${ NUM_REPOS } repos...` ) ;
39+
40+ for ( let i = 0 ; i < NUM_REPOS ; i ++ ) {
41+ await prisma . repo . create ( {
42+ data : {
43+ name : `test-repo-${ i } ` ,
44+ isFork : false ,
45+ isArchived : false ,
46+ metadata : { } ,
47+ cloneUrl : `https://github.com/test-org/test-repo-${ i } ` ,
48+ webUrl : `https://github.com/test-org/test-repo-${ i } ` ,
49+ orgId,
50+ external_id : `test-repo-${ i } ` ,
51+ external_codeHostType : 'github' ,
52+ external_codeHostUrl : 'https://github.com' ,
53+ connections : {
54+ create : {
55+ connectionId : connection . id ,
56+ }
57+ }
58+ }
59+ } ) ;
60+ }
61+
62+ logger . info ( `Created ${ NUM_REPOS } repos.` ) ;
63+ }
64+ } ;
0 commit comments