@@ -10,8 +10,6 @@ import chalk from "chalk";
1010
1111dotenv . config ( ) ;
1212
13- const CLI_RUN_ID = randomUUID ( ) ;
14-
1513const CREATE_DB_WORKER_URL =
1614 process . env . CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io" ;
1715const CLAIM_DB_WORKER_URL =
@@ -20,15 +18,15 @@ const CLAIM_DB_WORKER_URL =
2018// Track pending analytics promises to ensure they complete before exit
2119const pendingAnalytics = [ ] ;
2220
23- async function sendAnalyticsToWorker ( eventName , properties ) {
21+ async function sendAnalyticsToWorker ( eventName , properties , cliRunId ) {
2422 const controller = new AbortController ( ) ;
2523 const timer = setTimeout ( ( ) => controller . abort ( ) , 5000 ) ;
2624
2725 const analyticsPromise = ( async ( ) => {
2826 try {
2927 const payload = {
3028 eventName,
31- properties : { distinct_id : CLI_RUN_ID , ...( properties || { } ) } ,
29+ properties : { distinct_id : cliRunId , ...( properties || { } ) } ,
3230 } ;
3331 await fetch ( `${ CREATE_DB_WORKER_URL } /analytics` , {
3432 method : "POST" ,
@@ -406,7 +404,7 @@ function handleError(message, extra = "") {
406404 process . exit ( 1 ) ;
407405}
408406
409- async function promptForRegion ( defaultRegion , userAgent ) {
407+ async function promptForRegion ( defaultRegion , userAgent , cliRunId ) {
410408 let regions ;
411409 try {
412410 regions = await getRegions ( ) ;
@@ -436,12 +434,12 @@ async function promptForRegion(defaultRegion, userAgent) {
436434 region : region ,
437435 "selection-method" : "interactive" ,
438436 "user-agent" : userAgent ,
439- } ) ;
437+ } , cliRunId ) ;
440438
441439 return region ;
442440}
443441
444- async function createDatabase ( name , region , userAgent , silent = false ) {
442+ async function createDatabase ( name , region , userAgent , cliRunId , silent = false ) {
445443 let s ;
446444 if ( ! silent ) {
447445 s = spinner ( ) ;
@@ -481,7 +479,7 @@ async function createDatabase(name, region, userAgent, silent = false) {
481479 "error-type" : "rate_limit" ,
482480 "status-code" : 429 ,
483481 "user-agent" : userAgent ,
484- } ) ;
482+ } , cliRunId ) ;
485483
486484 await flushAnalytics ( ) ;
487485 process . exit ( 1 ) ;
@@ -511,7 +509,7 @@ async function createDatabase(name, region, userAgent, silent = false) {
511509 "error-type" : "invalid_json" ,
512510 "status-code" : resp . status ,
513511 "user-agent" : userAgent ,
514- } ) ;
512+ } , cliRunId ) ;
515513
516514 await flushAnalytics ( ) ;
517515 process . exit ( 1 ) ;
@@ -583,7 +581,7 @@ async function createDatabase(name, region, userAgent, silent = false) {
583581 "error-type" : "api_error" ,
584582 "error-message" : result . error . message ,
585583 "user-agent" : userAgent ,
586- } ) ;
584+ } , cliRunId ) ;
587585
588586 await flushAnalytics ( ) ;
589587 process . exit ( 1 ) ;
@@ -641,11 +639,14 @@ async function createDatabase(name, region, userAgent, silent = false) {
641639 command : CLI_NAME ,
642640 region,
643641 utm_source : CLI_NAME ,
644- } ) ;
642+ } , cliRunId ) ;
645643}
646644
647645export async function main ( ) {
648646 try {
647+ // Generate unique ID for this CLI run
648+ const cliRunId = randomUUID ( ) ;
649+
649650 const rawArgs = process . argv . slice ( 2 ) ;
650651
651652 const { flags } = await parseArgs ( ) ;
@@ -673,7 +674,7 @@ export async function main() {
673674 platform : process . platform ,
674675 arch : process . arch ,
675676 "user-agent" : userAgent ,
676- } ) ;
677+ } , cliRunId ) ;
677678
678679 if ( ! flags . help && ! flags . json ) {
679680 await isOffline ( ) ;
@@ -705,7 +706,7 @@ export async function main() {
705706 region : region ,
706707 "selection-method" : "flag" ,
707708 "user-agent" : userAgent ,
708- } ) ;
709+ } , cliRunId ) ;
709710 }
710711
711712 if ( flags . interactive ) {
@@ -715,11 +716,11 @@ export async function main() {
715716 if ( flags . json ) {
716717 try {
717718 if ( chooseRegionPrompt ) {
718- region = await promptForRegion ( region , userAgent ) ;
719+ region = await promptForRegion ( region , userAgent , cliRunId ) ;
719720 } else {
720721 await validateRegion ( region , true ) ;
721722 }
722- const result = await createDatabase ( name , region , userAgent , true ) ;
723+ const result = await createDatabase ( name , region , userAgent , cliRunId , true ) ;
723724 console . log ( JSON . stringify ( result , null , 2 ) ) ;
724725 await flushAnalytics ( ) ;
725726 process . exit ( 0 ) ;
@@ -739,11 +740,11 @@ export async function main() {
739740 if ( flags . env ) {
740741 try {
741742 if ( chooseRegionPrompt ) {
742- region = await promptForRegion ( region , userAgent ) ;
743+ region = await promptForRegion ( region , userAgent , cliRunId ) ;
743744 } else {
744745 await validateRegion ( region , true ) ;
745746 }
746- const result = await createDatabase ( name , region , userAgent , true ) ;
747+ const result = await createDatabase ( name , region , userAgent , cliRunId , true ) ;
747748 if ( result . error ) {
748749 console . error ( result . message || "Unknown error" ) ;
749750 await flushAnalytics ( ) ;
@@ -770,12 +771,12 @@ export async function main() {
770771 )
771772 ) ;
772773 if ( chooseRegionPrompt ) {
773- region = await promptForRegion ( region , userAgent ) ;
774+ region = await promptForRegion ( region , userAgent , cliRunId ) ;
774775 }
775776
776777 region = await validateRegion ( region ) ;
777778
778- await createDatabase ( name , region , userAgent ) ;
779+ await createDatabase ( name , region , userAgent , cliRunId ) ;
779780
780781 outro ( "" ) ;
781782 await flushAnalytics ( ) ;
0 commit comments