Skip to content
Merged
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
2 changes: 1 addition & 1 deletion claim-db-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default {
const tokenData = (await tokenResponse.json()) as { access_token: string };

// Transfer project
const transferResponse = await fetch(`https://api.prisma.io/projects/${projectID}/transfer`, {
const transferResponse = await fetch(`https://api.prisma.io/v1/projects/${projectID}/transfer`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions create-db-worker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion create-db-worker/src/delete-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class DeleteDbWorkflow extends WorkflowEntrypoint<Env, Params> {

await step.sleep('wait 24 hours', '24 hours');

const res = await fetch(`https://api.prisma.io/projects/${projectID}`, {
const res = await fetch(`https://api.prisma.io/v1/projects/${projectID}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Expand Down
7 changes: 4 additions & 3 deletions create-db-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {

// --- Get available regions ---
if (url.pathname === '/regions' && request.method === 'GET') {
const regionsResponse = await fetch('https://api.prisma.io/regions', {
const regionsResponse = await fetch('https://api.prisma.io/v1/regions/postgres', {
headers: { Authorization: `Bearer ${env.INTEGRATION_TOKEN}` },
});
const regionsText = await regionsResponse.text();
Expand All @@ -55,7 +55,7 @@ export default {
}

const payload = JSON.stringify({ region, name });
const prismaResponse = await fetch('https://api.prisma.io/projects', {
const prismaResponse = await fetch('https://api.prisma.io/v1/projects', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -68,7 +68,8 @@ export default {

// Trigger delete workflow for the new project
try {
const projectID = JSON.parse(prismaText).id;
const response = JSON.parse(prismaText);
const projectID = response.data ? response.data.id : response.id;
await env.DELETE_DB_WORKFLOW.create({ params: { projectID } });
env.CREATE_DB_DATASET.writeDataPoint({
blobs: ['database_created'],
Expand Down
14 changes: 9 additions & 5 deletions create-db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export async function getRegions() {

try {
const data = await res.json();
return Array.isArray(data) ? data : data.data;
const regions = Array.isArray(data) ? data : data.data;
return regions.filter(region => region.status === 'available');
} catch (e) {
handleError("Failed to parse JSON from /regions endpoint.", e);
}
Expand Down Expand Up @@ -300,9 +301,11 @@ async function createDatabase(name, region) {

log.message("");
// Determine which connection string to display
const prismaConn = result.databases?.[0]?.connectionString;
const directConnDetails =
result.databases?.[0]?.apiKeys?.[0]?.ppgDirectConnection;
const database = result.data ? result.data.database : result.databases?.[0];
const prismaConn = database?.connectionString;
const directConnDetails = result.data
? database?.apiKeys?.[0]?.directConnection
: result.databases?.[0]?.apiKeys?.[0]?.ppgDirectConnection;
const directConn = directConnDetails
? `postgresql://${directConnDetails.user}:${directConnDetails.pass}@${directConnDetails.host}/postgres`
: null;
Expand Down Expand Up @@ -336,7 +339,8 @@ async function createDatabase(name, region) {
}

// Claim Database
const claimUrl = `${process.env.CLAIM_DB_WORKER_URL || "https://create-db.prisma.io"}?projectID=${result.id}&utm_source=${CLI_NAME}&utm_medium=cli`;
const projectId = result.data ? result.data.id : result.id;
const claimUrl = `${process.env.CLAIM_DB_WORKER_URL}?projectID=${projectId}&utm_source=${CLI_NAME}&utm_medium=cli`;
const clickableUrl = terminalLink(claimUrl, claimUrl, { fallback: false });
log.info(`${chalk.white(chalk.bold("✅ Claim your database:"))}`);

Expand Down
Loading