From 67e8db7b9dc8b84228bb76d80e8addcd92ded062 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Thu, 9 Oct 2025 10:48:50 -0400 Subject: [PATCH 1/7] fix: empty commit From 286eece04cc6b01999b451df235fdd865c84c3a5 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 24 Oct 2025 11:06:12 -0400 Subject: [PATCH 2/7] fix: pnpm fixed --- create-db/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-db/index.js b/create-db/index.js index cbc784a..b04c35c 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -618,7 +618,7 @@ async function createDatabase(name, region, userAgent, silent = false) { }); } -async function main() { +export async function main() { try { const rawArgs = process.argv.slice(2); From ae29d98282151505ac43b1a3cd281b82597b5cce Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 24 Oct 2025 11:18:20 -0400 Subject: [PATCH 3/7] test: test package updates --- .github/workflows/preview.yml | 17 ++++++++++++++--- .github/workflows/release.yml | 27 ++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index b2cf177..155a0e3 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -96,17 +96,28 @@ jobs: echo "Using CLAIM_DB_WORKER_URL=$CLAIM_DB_WORKER_URL" echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}" - for pkg in $WORKSPACES; do + # First, update create-db version and publish it + cd create-db + npm version prerelease --preid "$PRE_TAG" --no-git-tag-version + NEW_VERSION=$(node -p "require('./package.json').version") + pnpm publish --access public --tag pr${{ github.event.number }} --no-git-checks + cd .. + + # Then update create-pg and create-postgres to use the new create-db version + for pkg in create-pg create-postgres; do cd "$pkg" export CREATE_DB_WORKER_URL export CLAIM_DB_WORKER_URL export POSTHOG_API_HOST="${POSTHOG_API_HOST}" export POSTHOG_API_KEY="${POSTHOG_API_KEY}" - + + # Update dependency to use the published version instead of workspace:* + npm pkg set dependencies.create-db="$NEW_VERSION" + npm version prerelease \ --preid "$PRE_TAG" \ --no-git-tag-version - pnpm publish --access public --tag pr${{ github.event.number }} + pnpm publish --access public --tag pr${{ github.event.number }} --no-git-checks cd - >/dev/null done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e533c5..7f5e6af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,17 +48,34 @@ jobs: echo "Using CLAIM_DB_WORKER_URL=${CLAIM_DB_WORKER_URL}" echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}" - for pkg in $WORKSPACES; do + # First, publish create-db + echo "Publishing create-db to npm..." + cd create-db + export POSTHOG_API_HOST="${{ secrets.POSTHOG_API_HOST }}" + export POSTHOG_API_KEY="${{ secrets.POSTHOG_API_KEY }}" + CREATE_DB_VERSION=$(node -p "require('./package.json').version") + if ! pnpm publish --access public --no-git-checks; then + echo "Publish failed, trying to bump version and retry..." + npm version patch --no-git-tag-version + CREATE_DB_VERSION=$(node -p "require('./package.json').version") + pnpm publish --access public --no-git-checks || echo "Publish failed again for create-db" + fi + cd .. + + # Then publish create-pg and create-postgres with resolved dependencies + for pkg in create-pg create-postgres; do echo "Publishing $pkg to npm..." cd "$pkg" export POSTHOG_API_HOST="${{ secrets.POSTHOG_API_HOST }}" export POSTHOG_API_KEY="${{ secrets.POSTHOG_API_KEY }}" - # pnpm publish --access public || echo "Publish failed for $pkg" - # First try to publish - if ! pnpm publish --access public; then + + # Update dependency to use the published version instead of workspace:* + npm pkg set dependencies.create-db="$CREATE_DB_VERSION" + + if ! pnpm publish --access public --no-git-checks; then echo "Publish failed, trying to bump version and retry..." npm version patch --no-git-tag-version - pnpm publish --access public || echo "Publish failed again for $pkg" + pnpm publish --access public --no-git-checks || echo "Publish failed again for $pkg" fi cd - >/dev/null done From c2f773f5272a9d93f3efb2fd82d10c0184168ece Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 24 Oct 2025 11:20:35 -0400 Subject: [PATCH 4/7] fix: workflow changes reverted --- .github/workflows/preview.yml | 17 +++-------------- .github/workflows/release.yml | 27 +++++---------------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 155a0e3..b2cf177 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -96,28 +96,17 @@ jobs: echo "Using CLAIM_DB_WORKER_URL=$CLAIM_DB_WORKER_URL" echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}" - # First, update create-db version and publish it - cd create-db - npm version prerelease --preid "$PRE_TAG" --no-git-tag-version - NEW_VERSION=$(node -p "require('./package.json').version") - pnpm publish --access public --tag pr${{ github.event.number }} --no-git-checks - cd .. - - # Then update create-pg and create-postgres to use the new create-db version - for pkg in create-pg create-postgres; do + for pkg in $WORKSPACES; do cd "$pkg" export CREATE_DB_WORKER_URL export CLAIM_DB_WORKER_URL export POSTHOG_API_HOST="${POSTHOG_API_HOST}" export POSTHOG_API_KEY="${POSTHOG_API_KEY}" - - # Update dependency to use the published version instead of workspace:* - npm pkg set dependencies.create-db="$NEW_VERSION" - + npm version prerelease \ --preid "$PRE_TAG" \ --no-git-tag-version - pnpm publish --access public --tag pr${{ github.event.number }} --no-git-checks + pnpm publish --access public --tag pr${{ github.event.number }} cd - >/dev/null done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f5e6af..3e533c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,34 +48,17 @@ jobs: echo "Using CLAIM_DB_WORKER_URL=${CLAIM_DB_WORKER_URL}" echo "Using POSTHOG_API_HOST=${POSTHOG_API_HOST}" - # First, publish create-db - echo "Publishing create-db to npm..." - cd create-db - export POSTHOG_API_HOST="${{ secrets.POSTHOG_API_HOST }}" - export POSTHOG_API_KEY="${{ secrets.POSTHOG_API_KEY }}" - CREATE_DB_VERSION=$(node -p "require('./package.json').version") - if ! pnpm publish --access public --no-git-checks; then - echo "Publish failed, trying to bump version and retry..." - npm version patch --no-git-tag-version - CREATE_DB_VERSION=$(node -p "require('./package.json').version") - pnpm publish --access public --no-git-checks || echo "Publish failed again for create-db" - fi - cd .. - - # Then publish create-pg and create-postgres with resolved dependencies - for pkg in create-pg create-postgres; do + for pkg in $WORKSPACES; do echo "Publishing $pkg to npm..." cd "$pkg" export POSTHOG_API_HOST="${{ secrets.POSTHOG_API_HOST }}" export POSTHOG_API_KEY="${{ secrets.POSTHOG_API_KEY }}" - - # Update dependency to use the published version instead of workspace:* - npm pkg set dependencies.create-db="$CREATE_DB_VERSION" - - if ! pnpm publish --access public --no-git-checks; then + # pnpm publish --access public || echo "Publish failed for $pkg" + # First try to publish + if ! pnpm publish --access public; then echo "Publish failed, trying to bump version and retry..." npm version patch --no-git-tag-version - pnpm publish --access public --no-git-checks || echo "Publish failed again for $pkg" + pnpm publish --access public || echo "Publish failed again for $pkg" fi cd - >/dev/null done From 9b8531385b6a81a7d474b2d8cc7e73eb0a1143d3 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 24 Oct 2025 11:31:49 -0400 Subject: [PATCH 5/7] fix: pnpm warning fixed --- create-db/index.js | 5 ++++- create-db/package.json | 2 +- create-pg/package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/create-db/index.js b/create-db/index.js index b04c35c..9d7112c 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -752,4 +752,7 @@ export async function main() { } } -main(); +// Only run main() if this file is being executed directly, not when imported +if (import.meta.url === `file://${process.argv[1]}`) { + main(); +} diff --git a/create-db/package.json b/create-db/package.json index c91b870..534f50d 100644 --- a/create-db/package.json +++ b/create-db/package.json @@ -3,7 +3,7 @@ "version": "1.0.9", "description": "Instantly create a temporary Prisma Postgres database with one command, then claim and persist it in your Prisma Data Platform project when ready.", "main": "index.js", - "author": "", + "author": "prisma", "repository": { "type": "git", "url": "git+https://github.com/prisma/create-db.git" diff --git a/create-pg/package.json b/create-pg/package.json index 45bda5e..da2426a 100644 --- a/create-pg/package.json +++ b/create-pg/package.json @@ -3,7 +3,7 @@ "version": "1.0.9", "description": "Instantly create a temporary Prisma Postgres database with one command, then claim and persist it in your Prisma Data Platform project when ready.", "main": "index.js", - "author": "", + "author": "prisma", "repository": { "type": "git", "url": "git+https://github.com/prisma/create-db.git" From f667a75db41d2af7c614f4fc1153d3c61ad62578 Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 24 Oct 2025 11:42:41 -0400 Subject: [PATCH 6/7] test: analytics update test --- create-db/index.js | 66 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/create-db/index.js b/create-db/index.js index 9d7112c..79108a1 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -17,24 +17,44 @@ const CREATE_DB_WORKER_URL = const CLAIM_DB_WORKER_URL = process.env.CLAIM_DB_WORKER_URL || "https://create-db.prisma.io"; +// Track pending analytics promises to ensure they complete before exit +const pendingAnalytics = []; + async function sendAnalyticsToWorker(eventName, properties) { const controller = new AbortController(); - const timer = setTimeout(() => controller.abort(), 2000); - try { - const payload = { - eventName, - properties: { distinct_id: CLI_RUN_ID, ...(properties || {}) }, - }; - await fetch(`${CREATE_DB_WORKER_URL}/analytics`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(payload), - signal: controller.signal, - }); - } catch (error) { - } finally { - clearTimeout(timer); - } + const timer = setTimeout(() => controller.abort(), 5000); + + const analyticsPromise = (async () => { + try { + const payload = { + eventName, + properties: { distinct_id: CLI_RUN_ID, ...(properties || {}) }, + }; + await fetch(`${CREATE_DB_WORKER_URL}/analytics`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(payload), + signal: controller.signal, + }); + } catch (error) { + // Silently fail - analytics shouldn't block CLI + } finally { + clearTimeout(timer); + } + })(); + + pendingAnalytics.push(analyticsPromise); + return analyticsPromise; +} + +// Wait for all pending analytics with a timeout +async function flushAnalytics(maxWaitMs = 500) { + if (pendingAnalytics.length === 0) return; + + const timeout = new Promise((resolve) => setTimeout(resolve, maxWaitMs)); + const allAnalytics = Promise.all(pendingAnalytics); + + await Promise.race([allAnalytics, timeout]); } async function detectUserLocation() { @@ -135,6 +155,7 @@ async function isOffline() { `Check your internet connection or visit ${chalk.green("https://www.prisma-status.com/\n")}` ) ); + await flushAnalytics(); process.exit(1); } } @@ -205,6 +226,7 @@ Examples: ${chalk.gray(`npx ${CLI_NAME} --env --region us-east-1`)} ${chalk.gray(`npx ${CLI_NAME} --env >> .env`)} `); + await flushAnalytics(); process.exit(0); } @@ -405,6 +427,7 @@ async function promptForRegion(defaultRegion, userAgent) { if (region === null) { cancel(chalk.red("Operation cancelled.")); + await flushAnalytics(); process.exit(0); } @@ -460,6 +483,7 @@ async function createDatabase(name, region, userAgent, silent = false) { "user-agent": userAgent, }); + await flushAnalytics(); process.exit(1); } @@ -489,6 +513,7 @@ async function createDatabase(name, region, userAgent, silent = false) { "user-agent": userAgent, }); + await flushAnalytics(); process.exit(1); } @@ -560,6 +585,7 @@ async function createDatabase(name, region, userAgent, silent = false) { "user-agent": userAgent, }); + await flushAnalytics(); process.exit(1); } @@ -667,6 +693,7 @@ export async function main() { if (flags["list-regions"]) { await listRegions(); + await flushAnalytics(); process.exit(0); } @@ -694,6 +721,7 @@ export async function main() { } const result = await createDatabase(name, region, userAgent, true); console.log(JSON.stringify(result, null, 2)); + await flushAnalytics(); process.exit(0); } catch (e) { console.log( @@ -703,6 +731,7 @@ export async function main() { 2 ) ); + await flushAnalytics(); process.exit(1); } } @@ -717,13 +746,16 @@ export async function main() { const result = await createDatabase(name, region, userAgent, true); if (result.error) { console.error(result.message || "Unknown error"); + await flushAnalytics(); process.exit(1); } console.log(`DATABASE_URL="${result.directConnectionString}"`); console.error("\n# Claim your database at: " + result.claimUrl); + await flushAnalytics(); process.exit(0); } catch (e) { console.error(e?.message || String(e)); + await flushAnalytics(); process.exit(1); } } @@ -746,8 +778,10 @@ export async function main() { await createDatabase(name, region, userAgent); outro(""); + await flushAnalytics(); } catch (error) { console.error("Error:", error.message); + await flushAnalytics(); process.exit(1); } } From 4213a42f718e7c4292ea6d2045683e7c59b1aa5c Mon Sep 17 00:00:00 2001 From: Aidan McAlister Date: Fri, 24 Oct 2025 11:59:18 -0400 Subject: [PATCH 7/7] fix: moved cluRunId location --- create-db/index.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/create-db/index.js b/create-db/index.js index 79108a1..9dee98e 100755 --- a/create-db/index.js +++ b/create-db/index.js @@ -10,8 +10,6 @@ import chalk from "chalk"; dotenv.config(); -const CLI_RUN_ID = randomUUID(); - const CREATE_DB_WORKER_URL = process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io"; const CLAIM_DB_WORKER_URL = @@ -20,7 +18,7 @@ const CLAIM_DB_WORKER_URL = // Track pending analytics promises to ensure they complete before exit const pendingAnalytics = []; -async function sendAnalyticsToWorker(eventName, properties) { +async function sendAnalyticsToWorker(eventName, properties, cliRunId) { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 5000); @@ -28,7 +26,7 @@ async function sendAnalyticsToWorker(eventName, properties) { try { const payload = { eventName, - properties: { distinct_id: CLI_RUN_ID, ...(properties || {}) }, + properties: { distinct_id: cliRunId, ...(properties || {}) }, }; await fetch(`${CREATE_DB_WORKER_URL}/analytics`, { method: "POST", @@ -406,7 +404,7 @@ function handleError(message, extra = "") { process.exit(1); } -async function promptForRegion(defaultRegion, userAgent) { +async function promptForRegion(defaultRegion, userAgent, cliRunId) { let regions; try { regions = await getRegions(); @@ -436,12 +434,12 @@ async function promptForRegion(defaultRegion, userAgent) { region: region, "selection-method": "interactive", "user-agent": userAgent, - }); + }, cliRunId); return region; } -async function createDatabase(name, region, userAgent, silent = false) { +async function createDatabase(name, region, userAgent, cliRunId, silent = false) { let s; if (!silent) { s = spinner(); @@ -481,7 +479,7 @@ async function createDatabase(name, region, userAgent, silent = false) { "error-type": "rate_limit", "status-code": 429, "user-agent": userAgent, - }); + }, cliRunId); await flushAnalytics(); process.exit(1); @@ -511,7 +509,7 @@ async function createDatabase(name, region, userAgent, silent = false) { "error-type": "invalid_json", "status-code": resp.status, "user-agent": userAgent, - }); + }, cliRunId); await flushAnalytics(); process.exit(1); @@ -583,7 +581,7 @@ async function createDatabase(name, region, userAgent, silent = false) { "error-type": "api_error", "error-message": result.error.message, "user-agent": userAgent, - }); + }, cliRunId); await flushAnalytics(); process.exit(1); @@ -641,11 +639,14 @@ async function createDatabase(name, region, userAgent, silent = false) { command: CLI_NAME, region, utm_source: CLI_NAME, - }); + }, cliRunId); } export async function main() { try { + // Generate unique ID for this CLI run + const cliRunId = randomUUID(); + const rawArgs = process.argv.slice(2); const { flags } = await parseArgs(); @@ -673,7 +674,7 @@ export async function main() { platform: process.platform, arch: process.arch, "user-agent": userAgent, - }); + }, cliRunId); if (!flags.help && !flags.json) { await isOffline(); @@ -705,7 +706,7 @@ export async function main() { region: region, "selection-method": "flag", "user-agent": userAgent, - }); + }, cliRunId); } if (flags.interactive) { @@ -715,11 +716,11 @@ export async function main() { if (flags.json) { try { if (chooseRegionPrompt) { - region = await promptForRegion(region, userAgent); + region = await promptForRegion(region, userAgent, cliRunId); } else { await validateRegion(region, true); } - const result = await createDatabase(name, region, userAgent, true); + const result = await createDatabase(name, region, userAgent, cliRunId, true); console.log(JSON.stringify(result, null, 2)); await flushAnalytics(); process.exit(0); @@ -739,11 +740,11 @@ export async function main() { if (flags.env) { try { if (chooseRegionPrompt) { - region = await promptForRegion(region, userAgent); + region = await promptForRegion(region, userAgent, cliRunId); } else { await validateRegion(region, true); } - const result = await createDatabase(name, region, userAgent, true); + const result = await createDatabase(name, region, userAgent, cliRunId, true); if (result.error) { console.error(result.message || "Unknown error"); await flushAnalytics(); @@ -770,12 +771,12 @@ export async function main() { ) ); if (chooseRegionPrompt) { - region = await promptForRegion(region, userAgent); + region = await promptForRegion(region, userAgent, cliRunId); } region = await validateRegion(region); - await createDatabase(name, region, userAgent); + await createDatabase(name, region, userAgent, cliRunId); outro(""); await flushAnalytics();