From b6441dd7252db92ddabd8c13bf0aa2ab87a92107 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Thu, 13 Nov 2025 11:25:22 -0500 Subject: [PATCH 1/4] feat: accelerate removed --- create-db/index.js | 203 ++++++++++++++++++++++++++------------------- 1 file changed, 118 insertions(+), 85 deletions(-) diff --git a/create-db/index.js b/create-db/index.js index 9dee98e..b7b3753 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -429,17 +429,27 @@ async function promptForRegion(defaultRegion, userAgent, cliRunId) { process.exit(0); } - void sendAnalyticsToWorker("create_db:region_selected", { - command: CLI_NAME, - region: region, - "selection-method": "interactive", - "user-agent": userAgent, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:region_selected", + { + command: CLI_NAME, + region: region, + "selection-method": "interactive", + "user-agent": userAgent, + }, + cliRunId + ); return region; } -async function createDatabase(name, region, userAgent, cliRunId, silent = false) { +async function createDatabase( + name, + region, + userAgent, + cliRunId, + silent = false +) { let s; if (!silent) { s = spinner(); @@ -473,13 +483,17 @@ async function createDatabase(name, region, userAgent, cliRunId, silent = false) ); } - void sendAnalyticsToWorker("create_db:database_creation_failed", { - command: CLI_NAME, - region: region, - "error-type": "rate_limit", - "status-code": 429, - "user-agent": userAgent, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:database_creation_failed", + { + command: CLI_NAME, + region: region, + "error-type": "rate_limit", + "status-code": 429, + "user-agent": userAgent, + }, + cliRunId + ); await flushAnalytics(); process.exit(1); @@ -503,13 +517,17 @@ async function createDatabase(name, region, userAgent, cliRunId, silent = false) s.stop("Unexpected response from create service."); } - void sendAnalyticsToWorker("create_db:database_creation_failed", { - command: CLI_NAME, - region, - "error-type": "invalid_json", - "status-code": resp.status, - "user-agent": userAgent, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:database_creation_failed", + { + command: CLI_NAME, + region, + "error-type": "invalid_json", + "status-code": resp.status, + "user-agent": userAgent, + }, + cliRunId + ); await flushAnalytics(); process.exit(1); @@ -543,8 +561,7 @@ async function createDatabase(name, region, userAgent, cliRunId, silent = false) if (silent && !result.error) { const jsonResponse = { - connectionString: prismaConn, - directConnectionString: directConn, + connectionString: directConn, claimUrl: claimUrl, deletionDate: expiryDate.toISOString(), region: database?.region?.id || region, @@ -575,13 +592,17 @@ async function createDatabase(name, region, userAgent, cliRunId, silent = false) ); } - void sendAnalyticsToWorker("create_db:database_creation_failed", { - command: CLI_NAME, - region: region, - "error-type": "api_error", - "error-message": result.error.message, - "user-agent": userAgent, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:database_creation_failed", + { + command: CLI_NAME, + region: region, + "error-type": "api_error", + "error-message": result.error.message, + "user-agent": userAgent, + }, + cliRunId + ); await flushAnalytics(); process.exit(1); @@ -593,53 +614,44 @@ async function createDatabase(name, region, userAgent, cliRunId, silent = false) const expiryFormatted = expiryDate.toLocaleString(); + log.message(""); + log.info(chalk.bold("Database Connection")); log.message(""); - log.info(chalk.bold("Connect to your database →")); - - if (prismaConn) { - log.message( - chalk.magenta(" Use this connection string optimized for Prisma ORM:") - ); - log.message(" " + chalk.yellow(prismaConn)); - log.message(""); - } - + // Direct connection (only output this one) if (directConn) { - log.message( - chalk.cyan(" Use this connection string for everything else:") - ); + log.message(chalk.cyan(" Connection String:")); log.message(" " + chalk.yellow(directConn)); log.message(""); } else { - log.warning( - chalk.yellow( - "Direct connection details are not available in the API response." - ) - ); + log.warning(chalk.yellow(" Connection details are not available.")); + log.message(""); } + // prismaConn is still available as a variable but not displayed + + // Claim database section const clickableUrl = terminalLink(claimUrl, claimUrl, { fallback: false }); - log.success(`${chalk.bold("Claim your database →")}`); - log.message( - chalk.cyan(" Want to keep your database? Claim for free via this link:") - ); + log.success(chalk.bold("Claim Your Database")); + log.message(chalk.cyan(" Keep your database for free:")); log.message(" " + chalk.yellow(clickableUrl)); log.message( chalk.italic( chalk.gray( - " Your database will be deleted on " + - expiryFormatted + - " if not claimed." + ` Database will be deleted on ${expiryFormatted} if not claimed.` ) ) ); - void sendAnalyticsToWorker("create_db:database_created", { - command: CLI_NAME, - region, - utm_source: CLI_NAME, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:database_created", + { + command: CLI_NAME, + region, + utm_source: CLI_NAME, + }, + cliRunId + ); } export async function main() { @@ -659,22 +671,27 @@ export async function main() { userAgent = `${userEnvVars.PRISMA_ACTOR_NAME}/${userEnvVars.PRISMA_ACTOR_PROJECT}`; } - void sendAnalyticsToWorker("create_db:cli_command_ran", { - command: CLI_NAME, - "full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(), - "has-region-flag": rawArgs.includes("--region") || rawArgs.includes("-r"), - "has-interactive-flag": - rawArgs.includes("--interactive") || rawArgs.includes("-i"), - "has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"), - "has-list-regions-flag": rawArgs.includes("--list-regions"), - "has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"), - "has-env-flag": rawArgs.includes("--env") || rawArgs.includes("-e"), - "has-user-agent-from-env": !!userAgent, - "node-version": process.version, - platform: process.platform, - arch: process.arch, - "user-agent": userAgent, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:cli_command_ran", + { + command: CLI_NAME, + "full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(), + "has-region-flag": + rawArgs.includes("--region") || rawArgs.includes("-r"), + "has-interactive-flag": + rawArgs.includes("--interactive") || rawArgs.includes("-i"), + "has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"), + "has-list-regions-flag": rawArgs.includes("--list-regions"), + "has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"), + "has-env-flag": rawArgs.includes("--env") || rawArgs.includes("-e"), + "has-user-agent-from-env": !!userAgent, + "node-version": process.version, + platform: process.platform, + arch: process.arch, + "user-agent": userAgent, + }, + cliRunId + ); if (!flags.help && !flags.json) { await isOffline(); @@ -701,12 +718,16 @@ export async function main() { if (flags.region) { region = flags.region; - void sendAnalyticsToWorker("create_db:region_selected", { - command: CLI_NAME, - region: region, - "selection-method": "flag", - "user-agent": userAgent, - }, cliRunId); + void sendAnalyticsToWorker( + "create_db:region_selected", + { + command: CLI_NAME, + region: region, + "selection-method": "flag", + "user-agent": userAgent, + }, + cliRunId + ); } if (flags.interactive) { @@ -720,7 +741,13 @@ export async function main() { } else { await validateRegion(region, true); } - const result = await createDatabase(name, region, userAgent, cliRunId, true); + const result = await createDatabase( + name, + region, + userAgent, + cliRunId, + true + ); console.log(JSON.stringify(result, null, 2)); await flushAnalytics(); process.exit(0); @@ -744,13 +771,19 @@ export async function main() { } else { await validateRegion(region, true); } - const result = await createDatabase(name, region, userAgent, cliRunId, true); + const result = await createDatabase( + name, + region, + userAgent, + cliRunId, + true + ); if (result.error) { console.error(result.message || "Unknown error"); await flushAnalytics(); process.exit(1); } - console.log(`DATABASE_URL="${result.directConnectionString}"`); + console.log(`DATABASE_URL="${result.connectionString}"`); console.error("\n# Claim your database at: " + result.claimUrl); await flushAnalytics(); process.exit(0); From 5c69cae213a14656baea2c911151a0315d67c8a4 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Thu, 13 Nov 2025 11:30:49 -0500 Subject: [PATCH 2/4] fix: updated run --- create-db/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/create-db/index.js b/create-db/index.js index b7b3753..0910c7d 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -820,7 +820,7 @@ export async function main() { } } -// Only run main() if this file is being executed directly, not when imported -if (import.meta.url === `file://${process.argv[1]}`) { - main(); +// Run main() if this file is being executed directly +if (import.meta.url.endsWith('/index.js') || process.argv[1] === import.meta.url.replace('file://', '')) { + main().catch(console.error); } From ab9e3cb00628850c3b15f948ba2193b10d6ff058 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Thu, 13 Nov 2025 11:36:43 -0500 Subject: [PATCH 3/4] fix: possible pnpx fix --- create-db/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/create-db/index.js b/create-db/index.js index 0910c7d..697a47e 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -821,6 +821,14 @@ export async function main() { } // Run main() if this file is being executed directly -if (import.meta.url.endsWith('/index.js') || process.argv[1] === import.meta.url.replace('file://', '')) { +const isDirectExecution = + import.meta.url.endsWith("/index.js") || + process.argv[1] === import.meta.url.replace("file://", "") || + process.argv[1].includes("create-db") || + process.argv[1].includes("create-pg") || + process.argv[1].includes("create-postgres"); + +if (isDirectExecution && !process.env.__CREATE_DB_EXECUTING) { + process.env.__CREATE_DB_EXECUTING = "true"; main().catch(console.error); } From 1aa2c312450c86fdefa510bede60f6fe32737690 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Thu, 13 Nov 2025 11:40:39 -0500 Subject: [PATCH 4/4] chore: coderabbit --- create-db/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/create-db/index.js b/create-db/index.js index 697a47e..d036c6b 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -535,7 +535,6 @@ async function createDatabase( const database = result.data ? result.data.database : result.databases?.[0]; const projectId = result.data ? result.data.id : result.id; - const prismaConn = database?.connectionString; const directConnDetails = result.data ? database?.apiKeys?.[0]?.directConnection @@ -628,7 +627,6 @@ async function createDatabase( log.message(""); } - // prismaConn is still available as a variable but not displayed // Claim database section const clickableUrl = terminalLink(claimUrl, claimUrl, { fallback: false }); @@ -832,3 +830,7 @@ if (isDirectExecution && !process.env.__CREATE_DB_EXECUTING) { process.env.__CREATE_DB_EXECUTING = "true"; main().catch(console.error); } + +// if (import.meta.url.endsWith('/index.js') || process.argv[1] === import.meta.url.replace('file://', '')) { +// main().catch(console.error); +// }