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"]]
}
169 changes: 169 additions & 0 deletions .github/workflows/publish-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: Preview & Publish all CLIs

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

env:
# each folder under the repo root that contains one of your CLIs
WORKSPACES: create-db create-pg create-postgres
# each folder under the repo root that contains one of your CF Workers
CF_WORKERS: create-db-worker claim-db-worker

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
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: ❌ Disable pnpm git-checks
run: pnpm config set git-checks false

- name: 📄 Copy README to child CLIs
run: |
for pkg in create-pg create-postgres; do
cp create-db/README.md $pkg/README.md
done

- name: ☁️ Deploy CF Workers (preview)
id: deploy-workers-preview
env:
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
run: |
PRE_TAG="pr${{ github.event.number }}-${{ github.event.pull_request.head.ref }}-${{ github.run_id }}"
echo "PRE_TAG=$PRE_TAG" >> $GITHUB_ENV

for worker in $CF_WORKERS; do
echo "› deploying $worker → env $PRE_TAG"
resp=$(wrangler publish \
--env "$PRE_TAG" \
--account-id "$CF_ACCOUNT_ID" \
--api-token "$CF_API_TOKEN" \
--json)
url=$(echo "$resp" | grep -Po '"url":"\K[^"]+')
if [ "$worker" = "create-db-worker" ]; then
echo "create_db_worker_url=$url" >> $GITHUB_OUTPUT
else
echo "claim_db_worker_url=$url" >> $GITHUB_OUTPUT
fi
done

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

- name: 🚀 Bump & publish previews
env:
NPM_TOKEN: ${{ secrets.CREATE_DB_TOKEN_NPM }}
CREATE_DB_WORKER_URL: ${{ steps.deploy-workers-preview.outputs.create_db_worker_url }}
CLAIM_DB_WORKER_URL: ${{ steps.deploy-workers-preview.outputs.claim_db_worker_url }}
run: |
for pkg in $WORKSPACES; do
echo "› $pkg → bumping & publishing preview @$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 == 'push'
needs: preview
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: 📄 Copy README to child CLIs
run: |
for pkg in create-pg create-postgres; do
cp create-db/README.md $pkg/README.md
done

- 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
env:
NPM_TOKEN: ${{ secrets.CREATE_DB_TOKEN_NPM }}
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}
run: |
for pkg in $WORKSPACES; do
echo "› publishing $pkg"
cd $pkg
pnpm publish --access public
cd - >/dev/null
done

- name: ☁️ Deploy CF Workers (production)
env:
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
run: |
for worker in $CF_WORKERS; do
echo "› deploying $worker to production"
cd $worker
wrangler publish \
--account-id $CF_ACCOUNT_ID \
--api-token $CF_API_TOKEN
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"],
};
15 changes: 11 additions & 4 deletions create-db-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ export { DeleteDbWorkflow };
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
// --- Rate limiting ---
const { success } = await env.CREATE_DB_RATE_LIMITER.limit({ key: request.url })
const { success } = await env.CREATE_DB_RATE_LIMITER.limit({ key: request.url });

if (!success) {
return new Response(`429 Failure - rate limit exceeded for ${request.url}`, { status: 429 });
}


const url = new URL(request.url);

// --- Health check route ---
if (url.pathname === '/health' && request.method === 'GET') {
return new Response(JSON.stringify({ status: 'ok', service: 'create-db', timestamp: Date.now() }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
}

// --- Get available regions ---
if (url.pathname === '/regions' && request.method === 'GET') {
const regionsResponse = await fetch('https://api.prisma.io/regions', {
Expand Down Expand Up @@ -64,8 +71,8 @@ export default {
const projectID = JSON.parse(prismaText).id;
await env.DELETE_DB_WORKFLOW.create({ params: { projectID } });
env.CREATE_DB_DATASET.writeDataPoint({
blobs: ["database_created"],
indexes: ["create_db"]
blobs: ['database_created'],
indexes: ['create_db'],
});
} catch (e) {
console.error('Error parsing prismaText or triggering workflow:', e);
Expand Down
3 changes: 1 addition & 2 deletions create-db-worker/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable */
// Generated by Wrangler by running `wrangler types` (hash: d48bd8fb2abdc865acfb1543cf121ab8)
// Generated by Wrangler by running `wrangler types` (hash: 3f56097be8c168953b53c223c74e988f)
// Runtime types generated with [email protected] 2025-06-27
declare namespace Cloudflare {
interface Env {
CREATE_DB_RATE_LIMIT_KV: KVNamespace;
INTEGRATION_TOKEN: string;
CREATE_DB_DATASET: AnalyticsEngineDataset;
CREATE_DB_RATE_LIMITER: RateLimit;
DELETE_DB_WORKFLOW: Workflow;
Expand Down
Loading
Loading