create-db 0.0.11-pr27-feat-posthog-16472140508.0 → 0.0.11
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/README.md +87 -29
- package/demo.gif +0 -0
- package/index.js +4 -71
- package/package.json +2 -2
- package/analytics.js +0 -60
package/README.md
CHANGED
|
@@ -1,50 +1,108 @@
|
|
|
1
|
-
|
|
1
|
+
## **What is `create-db`?**
|
|
2
2
|
|
|
3
|
-
CLI tool
|
|
3
|
+
`create-db` is an open-source CLI tool that provisions [**temporary Prisma Postgres databases**](https://www.prisma.io/postgres?utm_source=create_db_npm_docs) with a single command.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Each database is available for **24 hours** by default. To keep the database permanently, you can **claim it for free** using the URL displayed in the CLI output.
|
|
8
|
+
|
|
9
|
+
This tool is designed for developers who need a fast way to test, prototype, or integrate Prisma Postgres without manual setup or creating an account.
|
|
10
|
+
|
|
11
|
+
## **Installation and usage**
|
|
12
|
+
|
|
13
|
+
There is no need to install the tool globally. Simply run:
|
|
6
14
|
|
|
7
15
|
```bash
|
|
8
|
-
npx create-db
|
|
9
|
-
npx create-db --region eu-west-1 # Custom region
|
|
10
|
-
npx create-db --i # Interactive region selection
|
|
16
|
+
npx create-db@latest
|
|
11
17
|
```
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
You can also use the following aliases:
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
```bash
|
|
22
|
+
npx create-pg@latest
|
|
23
|
+
npx create-postgres@latest
|
|
24
|
+
```
|
|
18
25
|
|
|
19
|
-
##
|
|
26
|
+
## **Examples**
|
|
20
27
|
|
|
21
28
|
```bash
|
|
22
|
-
|
|
29
|
+
npx create-db # Creates a database in the default region
|
|
30
|
+
npx create-db --region eu-west-1 # Creates a database in a specific region
|
|
31
|
+
npx create-db --i # Interactive region selection
|
|
32
|
+
|
|
23
33
|
```
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
## **Available options**
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
# LOCAL
|
|
29
|
-
CREATE_DB_WORKER_URL="http://127.0.0.1:8787"
|
|
30
|
-
CLAIM_DB_WORKER_URL="http://127.0.0.1:8787"
|
|
37
|
+
You can run `npx create-db --help` or `npx create-db -h` to see all the available CLI options:
|
|
31
38
|
|
|
32
|
-
# PROD
|
|
33
|
-
# CLAIM_DB_WORKER_URL="https://create-db.prisma.io"
|
|
34
|
-
# CREATE_DB_WORKER_URL="https://create-db-temp.prisma.io"
|
|
35
39
|
```
|
|
40
|
+
npx create-db [options]
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
--region <region>, -r <region> Specify a region
|
|
44
|
+
Available regions:
|
|
45
|
+
ap-southeast-1, ap-northeast-1,
|
|
46
|
+
eu-central-1, eu-west-3,
|
|
47
|
+
us-east-1, us-west-1
|
|
48
|
+
|
|
49
|
+
--interactive, -i Run in interactive mode
|
|
36
50
|
|
|
37
|
-
|
|
51
|
+
--help, -h Show this help message
|
|
38
52
|
|
|
39
|
-
```env
|
|
40
|
-
CREATE_DB_WORKER_URL="http://127.0.0.1:9999"
|
|
41
|
-
CLAIM_DB_WORKER_URL="http://127.0.0.1:8787"
|
|
42
53
|
```
|
|
43
54
|
|
|
44
|
-
##
|
|
55
|
+
## **CLI output example**
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
┌ 🚀 Creating a Prisma Postgres database
|
|
59
|
+
│
|
|
60
|
+
│ Provisioning a temporary database in us-east-1...
|
|
61
|
+
│
|
|
62
|
+
│ It will be automatically deleted in 24 hours, but you can claim it.
|
|
63
|
+
│
|
|
64
|
+
◇ Database created successfully!
|
|
65
|
+
│
|
|
66
|
+
● Connect to your database →
|
|
67
|
+
│
|
|
68
|
+
│ Prisma connection string:
|
|
69
|
+
│ prisma+postgres://accelerate.prisma-data.net/?api_key=...
|
|
70
|
+
│
|
|
71
|
+
│ Standard connection string:
|
|
72
|
+
│ postgresql://<username>:<password>@db.prisma.io:5432/postgres
|
|
73
|
+
│
|
|
74
|
+
◆ Claim your database →
|
|
75
|
+
│
|
|
76
|
+
│ Want to keep your database? Claim for free:
|
|
77
|
+
│ https://create-db.prisma.io?projectID=proj_...
|
|
78
|
+
└
|
|
45
79
|
|
|
46
|
-
```bash
|
|
47
|
-
npx create-db
|
|
48
|
-
npx create-db --region eu-west-1
|
|
49
|
-
npx create-db --i
|
|
50
80
|
```
|
|
81
|
+
|
|
82
|
+
## **Claiming a database**
|
|
83
|
+
|
|
84
|
+
When you create a database using `create-db`, it is temporary and will be deleted automatically after **24 hours**.
|
|
85
|
+
|
|
86
|
+
The CLI output includes a **claim URL** that allows you to keep the database permanently for free.
|
|
87
|
+
|
|
88
|
+
**What claiming does:**
|
|
89
|
+
|
|
90
|
+
- Moves the database into your Prisma Postgres account.
|
|
91
|
+
- Prevents it from being auto-deleted.
|
|
92
|
+
- Lets you continue using the database as a long-term instance.
|
|
93
|
+
|
|
94
|
+
Example:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
◆ Claim your database →
|
|
98
|
+
│
|
|
99
|
+
│ Want to keep your database? Claim for free:
|
|
100
|
+
|
|
|
101
|
+
│ https://create-db.prisma.io?projectID=proj_...
|
|
102
|
+
│
|
|
103
|
+
│ Your database will be deleted on 7/24/2025, 2:25:41 AM if not claimed.
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## **Next steps**
|
|
107
|
+
|
|
108
|
+
- Refer to the section in the official [Prisma Postgres documentation](https://www.prisma.io/docs/postgres/introduction/npx-create-db).
|
package/demo.gif
ADDED
|
Binary file
|
package/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import dotenv from "dotenv";
|
|
4
|
-
dotenv.config();
|
|
5
|
-
|
|
6
3
|
import {
|
|
7
4
|
select,
|
|
8
5
|
spinner,
|
|
@@ -10,10 +7,13 @@ import {
|
|
|
10
7
|
outro,
|
|
11
8
|
log,
|
|
12
9
|
cancel,
|
|
10
|
+
confirm,
|
|
13
11
|
} from "@clack/prompts";
|
|
14
12
|
import chalk from "chalk";
|
|
13
|
+
import dotenv from "dotenv";
|
|
15
14
|
import terminalLink from "terminal-link";
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
dotenv.config();
|
|
17
17
|
|
|
18
18
|
const CREATE_DB_WORKER_URL =
|
|
19
19
|
process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io";
|
|
@@ -265,17 +265,6 @@ async function promptForRegion(defaultRegion) {
|
|
|
265
265
|
process.exit(0);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
// Track region selection event
|
|
269
|
-
try {
|
|
270
|
-
await analytics.capture("create_db:region_selected", {
|
|
271
|
-
command: CLI_NAME,
|
|
272
|
-
region: region,
|
|
273
|
-
"selection-method": "interactive"
|
|
274
|
-
});
|
|
275
|
-
} catch (error) {
|
|
276
|
-
// Silently fail analytics
|
|
277
|
-
}
|
|
278
|
-
|
|
279
268
|
return region;
|
|
280
269
|
}
|
|
281
270
|
|
|
@@ -295,19 +284,6 @@ async function createDatabase(name, region) {
|
|
|
295
284
|
s.stop(
|
|
296
285
|
"We're experiencing a high volume of requests. Please try again later."
|
|
297
286
|
);
|
|
298
|
-
|
|
299
|
-
// Track database creation failure
|
|
300
|
-
try {
|
|
301
|
-
await analytics.capture("create_db:database_creation_failed", {
|
|
302
|
-
command: CLI_NAME,
|
|
303
|
-
region: region,
|
|
304
|
-
"error-type": "rate_limit",
|
|
305
|
-
"status-code": 429,
|
|
306
|
-
});
|
|
307
|
-
} catch (error) {
|
|
308
|
-
// Silently fail analytics
|
|
309
|
-
}
|
|
310
|
-
|
|
311
287
|
process.exit(1);
|
|
312
288
|
}
|
|
313
289
|
|
|
@@ -317,18 +293,6 @@ async function createDatabase(name, region) {
|
|
|
317
293
|
s.stop(
|
|
318
294
|
`Error creating database: ${result.error.message || "Unknown error"}`
|
|
319
295
|
);
|
|
320
|
-
|
|
321
|
-
// Track database creation failure
|
|
322
|
-
try {
|
|
323
|
-
await analytics.capture("create_db:database_creation_failed", {
|
|
324
|
-
command: CLI_NAME,
|
|
325
|
-
region: region,
|
|
326
|
-
"error-type": "api_error",
|
|
327
|
-
"error-message": result.error.message,
|
|
328
|
-
});
|
|
329
|
-
} catch (error) {
|
|
330
|
-
// Silently fail analytics
|
|
331
|
-
}
|
|
332
296
|
process.exit(1);
|
|
333
297
|
}
|
|
334
298
|
|
|
@@ -398,26 +362,6 @@ async function createDatabase(name, region) {
|
|
|
398
362
|
|
|
399
363
|
async function main() {
|
|
400
364
|
try {
|
|
401
|
-
const rawArgs = process.argv.slice(2);
|
|
402
|
-
log.message(
|
|
403
|
-
chalk.white(`POSTHOG: ${process.env.POSTHOG_API_KEY} ${process.env.POSTHOG_API_HOST}`)
|
|
404
|
-
);
|
|
405
|
-
try {
|
|
406
|
-
await analytics.capture("create_db:cli_command_ran", {
|
|
407
|
-
command: CLI_NAME,
|
|
408
|
-
"full-command": `${CLI_NAME} ${rawArgs.join(' ')}`.trim(),
|
|
409
|
-
"has-region-flag": rawArgs.includes('--region') || rawArgs.includes('-r'),
|
|
410
|
-
"has-interactive-flag": rawArgs.includes('--interactive') || rawArgs.includes('-i'),
|
|
411
|
-
"has-help-flag": rawArgs.includes('--help') || rawArgs.includes('-h'),
|
|
412
|
-
"has-list-regions-flag": rawArgs.includes('--list-regions'),
|
|
413
|
-
"node-version": process.version,
|
|
414
|
-
platform: process.platform,
|
|
415
|
-
arch: process.arch
|
|
416
|
-
});
|
|
417
|
-
} catch (error) {
|
|
418
|
-
// Silently fail analytics
|
|
419
|
-
}
|
|
420
|
-
|
|
421
365
|
// Parse command line arguments
|
|
422
366
|
const { flags } = await parseArgs();
|
|
423
367
|
|
|
@@ -442,17 +386,6 @@ async function main() {
|
|
|
442
386
|
// Apply command line flags
|
|
443
387
|
if (flags.region) {
|
|
444
388
|
region = flags.region;
|
|
445
|
-
|
|
446
|
-
// Track region selection via flag
|
|
447
|
-
try {
|
|
448
|
-
await analytics.capture("create_db:region_selected", {
|
|
449
|
-
command: CLI_NAME,
|
|
450
|
-
region: region,
|
|
451
|
-
"selection-method": "flag"
|
|
452
|
-
});
|
|
453
|
-
} catch (error) {
|
|
454
|
-
// Silently fail analytics
|
|
455
|
-
}
|
|
456
389
|
}
|
|
457
390
|
if (flags.interactive) {
|
|
458
391
|
chooseRegionPrompt = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-db",
|
|
3
|
-
"version": "0.0.11
|
|
3
|
+
"version": "0.0.11",
|
|
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": "",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"files": [
|
|
40
40
|
"index.js",
|
|
41
41
|
"README.md",
|
|
42
|
-
"
|
|
42
|
+
"demo.gif"
|
|
43
43
|
]
|
|
44
44
|
}
|
package/analytics.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "crypto";
|
|
2
|
-
|
|
3
|
-
class EventCaptureError extends Error {
|
|
4
|
-
constructor(event, status) {
|
|
5
|
-
super(`Failed to submit PostHog event '${event}': ${status}`);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class PosthogEventCapture {
|
|
10
|
-
async capture(eventName, properties = {}) {
|
|
11
|
-
const POSTHOG_CAPTURE_URL = process.env.POSTHOG_API_HOST
|
|
12
|
-
? process.env.POSTHOG_API_HOST + "/capture"
|
|
13
|
-
: null;
|
|
14
|
-
const POSTHOG_KEY = process.env.POSTHOG_API_KEY;
|
|
15
|
-
|
|
16
|
-
// Skip if environment variables are not set
|
|
17
|
-
if (!POSTHOG_CAPTURE_URL || !POSTHOG_KEY) {
|
|
18
|
-
if (process.env.NODE_ENV === "development") {
|
|
19
|
-
console.warn(
|
|
20
|
-
"Analytics skipped: POSTHOG_API_HOST or POSTHOG_API_KEY not set"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const payload = {
|
|
27
|
-
api_key: POSTHOG_KEY,
|
|
28
|
-
event: eventName,
|
|
29
|
-
distinct_id: randomUUID(),
|
|
30
|
-
properties: {
|
|
31
|
-
$process_person_profile: false,
|
|
32
|
-
...properties,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const response = await fetch(POSTHOG_CAPTURE_URL, {
|
|
38
|
-
method: "POST",
|
|
39
|
-
headers: {
|
|
40
|
-
"Content-Type": "application/json",
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify(payload),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
throw new EventCaptureError(eventName, response.statusText);
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
// Silently fail analytics to not disrupt user experience
|
|
50
|
-
if (process.env.NODE_ENV === "development") {
|
|
51
|
-
console.error("Analytics error:", error.message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Create a singleton instance
|
|
58
|
-
const analytics = new PosthogEventCapture();
|
|
59
|
-
|
|
60
|
-
export { analytics, EventCaptureError };
|