create-db 1.0.7-pr50-remove-replace-17274596200.0 ā 1.0.8-pr51-DC-4933-env-flag-17282359601.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +58 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -194,6 +194,7 @@ Options:
|
|
|
194
194
|
${chalk.yellow("--json, -j")} Output machine-readable JSON and exit
|
|
195
195
|
${chalk.yellow("--list-regions")} List available regions and exit
|
|
196
196
|
${chalk.yellow("--help, -h")} Show this help message
|
|
197
|
+
${chalk.yellow("--env, -e")} Outputs DATABASE_URL to the terminal
|
|
197
198
|
|
|
198
199
|
Examples:
|
|
199
200
|
${chalk.gray(`npx ${CLI_NAME} --region us-east-1`)}
|
|
@@ -215,12 +216,14 @@ async function parseArgs() {
|
|
|
215
216
|
"list-regions",
|
|
216
217
|
"interactive",
|
|
217
218
|
"json",
|
|
219
|
+
"env",
|
|
218
220
|
];
|
|
219
221
|
const shorthandMap = {
|
|
220
222
|
r: "region",
|
|
221
223
|
i: "interactive",
|
|
222
224
|
h: "help",
|
|
223
225
|
j: "json",
|
|
226
|
+
e: "env",
|
|
224
227
|
};
|
|
225
228
|
|
|
226
229
|
const exitWithError = (message) => {
|
|
@@ -293,6 +296,30 @@ async function parseArgs() {
|
|
|
293
296
|
return { flags };
|
|
294
297
|
}
|
|
295
298
|
|
|
299
|
+
function validateFlagCombinations(flags) {
|
|
300
|
+
const conflictingFlags = [
|
|
301
|
+
["env", "json"],
|
|
302
|
+
["list-regions", "env"],
|
|
303
|
+
["list-regions", "json"],
|
|
304
|
+
["list-regions", "interactive"],
|
|
305
|
+
["list-regions", "region"],
|
|
306
|
+
["interactive", "env"],
|
|
307
|
+
["interactive", "json"],
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
for (const [flag1, flag2] of conflictingFlags) {
|
|
311
|
+
if (flags[flag1] && flags[flag2]) {
|
|
312
|
+
console.error(
|
|
313
|
+
chalk.red.bold(
|
|
314
|
+
`\nā Error: Cannot use --${flag1} and --${flag2} together.\n`
|
|
315
|
+
)
|
|
316
|
+
);
|
|
317
|
+
console.error(chalk.gray("Use --help or -h to see available options.\n"));
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
296
323
|
export async function getRegions(returnJson = false) {
|
|
297
324
|
const url = `${CREATE_DB_WORKER_URL}/regions`;
|
|
298
325
|
const res = await fetch(url);
|
|
@@ -389,9 +416,9 @@ async function promptForRegion(defaultRegion, userAgent) {
|
|
|
389
416
|
return region;
|
|
390
417
|
}
|
|
391
418
|
|
|
392
|
-
async function createDatabase(name, region, userAgent,
|
|
419
|
+
async function createDatabase(name, region, userAgent, silent = false) {
|
|
393
420
|
let s;
|
|
394
|
-
if (!
|
|
421
|
+
if (!silent) {
|
|
395
422
|
s = spinner();
|
|
396
423
|
s.start("Creating your database...");
|
|
397
424
|
}
|
|
@@ -407,7 +434,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
407
434
|
});
|
|
408
435
|
|
|
409
436
|
if (resp.status === 429) {
|
|
410
|
-
if (
|
|
437
|
+
if (silent) {
|
|
411
438
|
return {
|
|
412
439
|
error: "rate_limit_exceeded",
|
|
413
440
|
message:
|
|
@@ -439,7 +466,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
439
466
|
raw = await resp.text();
|
|
440
467
|
result = JSON.parse(raw);
|
|
441
468
|
} catch (e) {
|
|
442
|
-
if (
|
|
469
|
+
if (silent) {
|
|
443
470
|
return {
|
|
444
471
|
error: "invalid_json",
|
|
445
472
|
message: "Unexpected response from create service.",
|
|
@@ -488,7 +515,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
488
515
|
const claimUrl = `${CLAIM_DB_WORKER_URL}?projectID=${projectId}&utm_source=${userAgent}&utm_medium=cli`;
|
|
489
516
|
const expiryDate = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
|
490
517
|
|
|
491
|
-
if (
|
|
518
|
+
if (silent && !result.error) {
|
|
492
519
|
const jsonResponse = {
|
|
493
520
|
connectionString: prismaConn,
|
|
494
521
|
directConnectionString: directConn,
|
|
@@ -507,7 +534,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
507
534
|
}
|
|
508
535
|
|
|
509
536
|
if (result.error) {
|
|
510
|
-
if (
|
|
537
|
+
if (silent) {
|
|
511
538
|
return {
|
|
512
539
|
error: "api_error",
|
|
513
540
|
message: result.error.message || "Unknown error",
|
|
@@ -593,6 +620,8 @@ async function main() {
|
|
|
593
620
|
|
|
594
621
|
const { flags } = await parseArgs();
|
|
595
622
|
|
|
623
|
+
validateFlagCombinations(flags);
|
|
624
|
+
|
|
596
625
|
let userAgent;
|
|
597
626
|
const userEnvVars = readUserEnvFile();
|
|
598
627
|
if (userEnvVars.PRISMA_ACTOR_NAME && userEnvVars.PRISMA_ACTOR_PROJECT) {
|
|
@@ -670,6 +699,29 @@ async function main() {
|
|
|
670
699
|
}
|
|
671
700
|
}
|
|
672
701
|
|
|
702
|
+
if (flags.env) {
|
|
703
|
+
try {
|
|
704
|
+
if (chooseRegionPrompt) {
|
|
705
|
+
region = await promptForRegion(region, userAgent);
|
|
706
|
+
} else {
|
|
707
|
+
await validateRegion(region, true);
|
|
708
|
+
}
|
|
709
|
+
const result = await createDatabase(name, region, userAgent, true);
|
|
710
|
+
if (result.error) {
|
|
711
|
+
console.error(result.message || "Unknown error");
|
|
712
|
+
process.exit(1);
|
|
713
|
+
}
|
|
714
|
+
process.stdout.write(`DATABASE_URL="${result.directConnectionString}"`);
|
|
715
|
+
process.stderr.write(
|
|
716
|
+
"\n\n# Claim your database at: " + result.claimUrl
|
|
717
|
+
);
|
|
718
|
+
process.exit(0);
|
|
719
|
+
} catch (e) {
|
|
720
|
+
console.error(e?.message || String(e));
|
|
721
|
+
process.exit(1);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
673
725
|
intro(chalk.cyan.bold("š Creating a Prisma Postgres database"));
|
|
674
726
|
log.message(
|
|
675
727
|
chalk.white(`Provisioning a temporary database in ${region}...`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8-pr51-DC-4933-env-flag-17282359601.0",
|
|
4
4
|
"description": "Instantly create a temporary Prisma Postgres database with one command, then claim and persist it in your Prisma Data Platform project when ready.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "",
|