Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
13 changes: 13 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/cli/changelog",
{ "repo": "https://github.com/prisma/create-db" }
],
"commit": false,
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["create-db-worker", "claim-db-worker"],
"linked": [["create-db", "create-db-worker", "claim-db-worker"]]
}
116 changes: 116 additions & 0 deletions .github/workflows/publish-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Preview & Publish all CLIs

on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- closed
push:
branches:
- main

env:
# each folder under the repo root that contains one of your CLIs
WORKSPACES: |
create-db
create-pg
create-postgres

jobs:
preview:
if: github.event_name == 'pull_request'
name: 🚧 Preview release (PR #${{ github.event.number }})
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout full history
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 🤐 Disable Husky
run: echo "HUSKY=0" >> $GITHUB_ENV

- name: 📦 Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: 🔧 Install dependencies
run: pnpm install

- name: 🔄 Disable pnpm git-checks
run: pnpm config set git-checks false

- name: 🔑 Configure npm auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc

- name: 🚀 Publish PR-tagged previews
run: |
PRE_TAG="pr${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.run_id }}"
for pkg in $WORKSPACES; do
echo "› publishing $pkg@$PRE_TAG"
cd $pkg
npm version prerelease \
--preid "$PRE_TAG" \
--no-git-tag-version
pnpm publish --access public --tag pr${{ github.event.number }}
cd - >/dev/null
done

- name: 🧹 Cleanup npm auth
run: rm -f ~/.npmrc

publish:
if: >
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true
name: 🚀 Bump & publish real releases
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout full & tags
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true

- name: 🤐 Disable Husky
run: echo "HUSKY=0" >> $GITHUB_ENV

- name: 📦 Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: 🔧 Install dependencies
run: pnpm install

- name: 🔄 Bump versions & generate changelogs
run: pnpm changeset version

- name: 💾 Commit & push version bump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git commit -am "chore: version packages [skip ci]" || echo "no version changes"
git push origin main --follow-tags

- name: 🔑 Configure npm auth
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc

- name: 🚀 Publish all real releases
run: |
for pkg in $WORKSPACES; do
echo "› publishing $pkg"
cd $pkg
pnpm publish --access public
cd - >/dev/null
done

- name: 🧹 Cleanup npm auth
run: rm -f ~/.npmrc
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm exec commitlint --edit ".git/COMMIT_EDITMSG"
6 changes: 6 additions & 0 deletions .husky/install.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Skip Husky install in production and CI
if (process.env.NODE_ENV === "production" || process.env.CI === "true") {
process.exit(0);
}
const husky = (await import("husky")).default;
console.log(husky());
4 changes: 4 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// commitlint.config.js
module.exports = {
extends: ["@commitlint/config-conventional"],
};
60 changes: 42 additions & 18 deletions create-db/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#!/usr/bin/env node

import { select, spinner, intro, outro, log, cancel, confirm } from "@clack/prompts";
import {
select,
spinner,
intro,
outro,
log,
cancel,
confirm,
} from "@clack/prompts";
import chalk from "chalk";
import dotenv from "dotenv";
import terminalLink from 'terminal-link';
import terminalLink from "terminal-link";
import clipboard from "clipboardy";

dotenv.config();
Expand Down Expand Up @@ -64,7 +72,7 @@ function parseArgs() {
// Get region from user input

async function promptForRegion(defaultRegion) {
const url = `${process.env.CREATE_DB_WORKER_URL}/regions`;
const url = `${process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io"}/regions`;
const res = await fetch(url);
let data;
try {
Expand All @@ -79,7 +87,8 @@ async function promptForRegion(defaultRegion) {
const region = await select({
message: "Choose a region:",
options: regions.map((r) => ({ value: r.id, label: r.id })),
initialValue: regions.find((r) => r.id === defaultRegion)?.id || regions[0]?.id,
initialValue:
regions.find((r) => r.id === defaultRegion)?.id || regions[0]?.id,
});

if (region === null) {
Expand All @@ -96,22 +105,29 @@ async function createDatabase(name, region, enableCopyPrompt = false) {
const s = spinner();
s.start("Setting up your database...");

const resp = await fetch(`${process.env.CREATE_DB_WORKER_URL}/create`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ region, name }),
});
const resp = await fetch(
`${process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io"}/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ region, name }),
}
);

// Rate limit exceeded
if (resp.status === 429) {
s.stop("We're experiencing a high volume of requests. Please try again later.");
s.stop(
"We're experiencing a high volume of requests. Please try again later."
);
process.exit(1);
}

const result = await resp.json();

if (result.error) {
s.stop(`Error creating database: ${result.error.message || "Unknown error"}`);
s.stop(
`Error creating database: ${result.error.message || "Unknown error"}`
);
process.exit(1);
}

Expand All @@ -128,14 +144,19 @@ async function createDatabase(name, region, enableCopyPrompt = false) {
log.message("");
log.success("Claim your database:");

const claimUrl = `${process.env.CLAIM_DB_WORKER_URL}?projectID=${result.id}`;
const clickableUrl = terminalLink(claimUrl, claimUrl, { fallback: false});
const claimUrl = `${process.env.CLAIM_DB_WORKER_URL || "https://create-db.prisma.io"}?projectID=${result.id}`;
const clickableUrl = terminalLink(claimUrl, claimUrl, { fallback: false });
log.message(" " + chalk.green(clickableUrl));
log.message(" " + chalk.red(`Expires: ${expiryFormatted}`) + chalk.gray(" (Claim to make permanent on your Prisma account)"));
log.message(
" " +
chalk.red(`Expires: ${expiryFormatted}`) +
chalk.gray(" (Claim to make permanent on your Prisma account)")
);

if (enableCopyPrompt) {
const shouldCopy = await confirm({
message: "Would you like to copy the connection string to your clipboard?",
message:
"Would you like to copy the connection string to your clipboard?",
initialValue: true,
});
if (shouldCopy) {
Expand Down Expand Up @@ -176,19 +197,22 @@ async function main() {
} else {
// Show minimal header for non-interactive mode
log.info(chalk.cyan.bold("🚀 Prisma Postgres Create DB"));
log.message(chalk.gray(`Creating a temporary Prisma Postgres database in ${region}...`));
log.message(
chalk.gray(
`Creating a temporary Prisma Postgres database in ${region}...`
)
);
log.message("");
}

// Create the database
await createDatabase(name, region, enableCopyPrompt);

outro("");

} catch (error) {
console.error("Error:", error.message);
process.exit(1);
}
}

main();
main();
31 changes: 27 additions & 4 deletions create-db/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
{
"name": "create-db",
"version": "0.0.1",
"description": "",
"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",
"keywords": [],
"author": "",
"repository": {
"type": "git",
"url": "git+https://github.com/prisma/create-db.git"
},
"bugs": {
"url": "https://github.com/prisma/create-db/issues"
},
"homepage": "https://github.com/prisma/create-db#readme",
"keywords": [
"prisma",
"postgres",
"cli",
"database",
"temporary"
],
"license": "ISC",
"type": "module",
"bin": {
"create-db": "./index.js"
"create-db": "./index.js",
"create-postgres": "./index.js",
"create-pg": "./index.js"
},
"dependencies": {
"@clack/prompts": "^0.11.0",
"chalk": "^4.1.2",
"clipboardy": "^4.0.0",
"dotenv": "^16.6.1",
"terminal-link": "^4.0.0"
}
},
"publishConfig": {
"access": "public"
},
"files": [
"index.js",
"README.md"
]
}
3 changes: 3 additions & 0 deletions create-pg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
node_modules
package-lock.json
50 changes: 50 additions & 0 deletions create-pg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Create DB CLI

CLI tool for creating temporary Prisma Postgres databases.

## Usage

```bash
npx create-db # Default region (us-east-1)
npx create-db --region eu-west-1 # Custom region
npx create-db --i # Interactive region selection
```

## Key Files

- **Main Logic:** [`index.js`](index.js) - Argument parsing, API requests, and output
- **Configuration:** [`package.json`](package.json) - CLI entry point and dependencies
- **Environment:** `.env` - Worker endpoints configuration

## Development

```bash
npm install
```

Create `.env` for local development:

```env
# LOCAL
CREATE_DB_WORKER_URL="http://127.0.0.1:8787"
CLAIM_DB_WORKER_URL="http://127.0.0.1:8787"

# PROD
# CREATE_DB_WORKER_URL="https://create-db-worker.raycast-0ef.workers.dev"
# CLAIM_DB_WORKER_URL="https://claim-db-worker.raycast-0ef.workers.dev"
```

If running both workers locally, use a different port for one and update the URL:

```env
CREATE_DB_WORKER_URL="http://127.0.0.1:9999"
CLAIM_DB_WORKER_URL="http://127.0.0.1:8787"
```

## Test Locally

```bash
npx create-db
npx create-db --region eu-west-1
npx create-db --i
```
3 changes: 3 additions & 0 deletions create-pg/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
import { main } from "create-db";
main();
Loading