alchemy 0.63.0 → 0.64.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/bin/alchemy.js +97 -87
- package/bin/commands/init.ts +1 -1
- package/bin/services/github-workflow.ts +2 -2
- package/lib/alchemy.d.ts +4 -0
- package/lib/alchemy.d.ts.map +1 -1
- package/lib/alchemy.js +10 -4
- package/lib/alchemy.js.map +1 -1
- package/lib/apply.d.ts +3 -0
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +11 -1
- package/lib/apply.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +3 -1
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bucket.d.ts +2 -1
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/bundle/cloudflare-internal.d.ts +6 -0
- package/lib/cloudflare/bundle/cloudflare-internal.d.ts.map +1 -0
- package/lib/cloudflare/bundle/cloudflare-internal.js +39 -0
- package/lib/cloudflare/bundle/cloudflare-internal.js.map +1 -0
- package/lib/cloudflare/bundle/nodejs-builtin-modules.d.ts +2 -0
- package/lib/cloudflare/bundle/nodejs-builtin-modules.d.ts.map +1 -0
- package/lib/cloudflare/bundle/nodejs-builtin-modules.js +9 -0
- package/lib/cloudflare/bundle/nodejs-builtin-modules.js.map +1 -0
- package/lib/cloudflare/bundle/plugin-als-external.d.ts +6 -0
- package/lib/cloudflare/bundle/plugin-als-external.d.ts.map +1 -0
- package/lib/cloudflare/bundle/plugin-als-external.js +12 -0
- package/lib/cloudflare/bundle/plugin-als-external.js.map +1 -0
- package/lib/cloudflare/bundle/plugin-hybrid-node-compat.d.ts +4 -1
- package/lib/cloudflare/bundle/plugin-hybrid-node-compat.d.ts.map +1 -1
- package/lib/cloudflare/bundle/plugin-hybrid-node-compat.js +23 -23
- package/lib/cloudflare/bundle/plugin-hybrid-node-compat.js.map +1 -1
- package/lib/cloudflare/bundle/plugin-node-compat.d.ts +11 -0
- package/lib/cloudflare/bundle/plugin-node-compat.d.ts.map +1 -0
- package/lib/cloudflare/bundle/plugin-node-compat.js +93 -0
- package/lib/cloudflare/bundle/plugin-node-compat.js.map +1 -0
- package/lib/cloudflare/cloudflare-env-proxy.js +1 -1
- package/lib/cloudflare/cloudflare-env-proxy.js.map +1 -1
- package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
- package/lib/cloudflare/compatibility-date.gen.js +1 -1
- package/lib/cloudflare/d1-local-migrations.js.map +1 -1
- package/lib/cloudflare/durable-object-namespace.d.ts +1 -0
- package/lib/cloudflare/durable-object-namespace.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.js +1 -1
- package/lib/cloudflare/hyperdrive.js.map +1 -1
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +80 -82
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-bundle.d.ts +6 -0
- package/lib/cloudflare/worker-bundle.d.ts.map +1 -1
- package/lib/cloudflare/worker-bundle.js +34 -10
- package/lib/cloudflare/worker-bundle.js.map +1 -1
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
- package/lib/cloudflare/worker-metadata.js +2 -1
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +24 -6
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +2 -4
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +16 -14
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/context.d.ts +3 -1
- package/lib/context.d.ts.map +1 -1
- package/lib/context.js +2 -2
- package/lib/context.js.map +1 -1
- package/lib/destroy.d.ts +8 -0
- package/lib/destroy.d.ts.map +1 -1
- package/lib/destroy.js +20 -4
- package/lib/destroy.js.map +1 -1
- package/lib/neon/project.d.ts.map +1 -1
- package/lib/neon/project.js +4 -5
- package/lib/neon/project.js.map +1 -1
- package/lib/planetscale/api/client.gen.d.ts +1750 -0
- package/lib/planetscale/api/client.gen.d.ts.map +1 -0
- package/lib/planetscale/api/client.gen.js +2401 -0
- package/lib/planetscale/api/client.gen.js.map +1 -0
- package/lib/planetscale/api/index.d.ts +3 -0
- package/lib/planetscale/api/index.d.ts.map +1 -0
- package/lib/planetscale/api/index.js +4 -0
- package/lib/planetscale/api/index.js.map +1 -0
- package/lib/planetscale/api/types.gen.d.ts +12156 -0
- package/lib/planetscale/api/types.gen.d.ts.map +1 -0
- package/lib/planetscale/api/types.gen.js +2 -0
- package/lib/planetscale/api/types.gen.js.map +1 -0
- package/lib/planetscale/branch.d.ts +5 -8
- package/lib/planetscale/branch.d.ts.map +1 -1
- package/lib/planetscale/branch.js +111 -97
- package/lib/planetscale/branch.js.map +1 -1
- package/lib/planetscale/database.d.ts +2 -6
- package/lib/planetscale/database.d.ts.map +1 -1
- package/lib/planetscale/database.js +157 -118
- package/lib/planetscale/database.js.map +1 -1
- package/lib/planetscale/index.d.ts +1 -1
- package/lib/planetscale/index.d.ts.map +1 -1
- package/lib/planetscale/index.js +1 -1
- package/lib/planetscale/index.js.map +1 -1
- package/lib/planetscale/password.d.ts +4 -7
- package/lib/planetscale/password.d.ts.map +1 -1
- package/lib/planetscale/password.js +71 -56
- package/lib/planetscale/password.js.map +1 -1
- package/lib/planetscale/utils.d.ts +8 -6
- package/lib/planetscale/utils.d.ts.map +1 -1
- package/lib/planetscale/utils.js +85 -70
- package/lib/planetscale/utils.js.map +1 -1
- package/lib/scope.d.ts +5 -1
- package/lib/scope.d.ts.map +1 -1
- package/lib/scope.js +11 -3
- package/lib/scope.js.map +1 -1
- package/lib/upstash/redis.js +1 -1
- package/lib/upstash/redis.js.map +1 -1
- package/lib/util/dedent.d.ts +3 -14
- package/lib/util/dedent.d.ts.map +1 -1
- package/lib/util/dedent.js +28 -52
- package/lib/util/dedent.js.map +1 -1
- package/lib/util/idempotent-spawn.d.ts.map +1 -1
- package/lib/util/idempotent-spawn.js +21 -2
- package/lib/util/idempotent-spawn.js.map +1 -1
- package/lib/util/xml.js +1 -1
- package/lib/util/xml.js.map +1 -1
- package/package.json +4 -3
- package/src/alchemy.ts +14 -6
- package/src/apply.ts +13 -1
- package/src/cloudflare/bindings.ts +3 -1
- package/src/cloudflare/bucket.ts +3 -1
- package/src/cloudflare/bundle/cloudflare-internal.ts +42 -0
- package/src/cloudflare/bundle/nodejs-builtin-modules.ts +14 -0
- package/src/cloudflare/bundle/plugin-als-external.ts +13 -0
- package/src/cloudflare/bundle/plugin-hybrid-node-compat.ts +29 -28
- package/src/cloudflare/bundle/plugin-node-compat.ts +114 -0
- package/src/cloudflare/cloudflare-env-proxy.ts +1 -1
- package/src/cloudflare/compatibility-date.gen.ts +1 -1
- package/src/cloudflare/d1-local-migrations.ts +2 -2
- package/src/cloudflare/durable-object-namespace.ts +1 -1
- package/src/cloudflare/hyperdrive.ts +1 -1
- package/src/cloudflare/website.ts +88 -89
- package/src/cloudflare/worker-bundle.ts +46 -9
- package/src/cloudflare/worker-metadata.ts +3 -1
- package/src/cloudflare/worker.ts +35 -7
- package/src/cloudflare/wrangler.json.ts +108 -110
- package/src/context.ts +5 -3
- package/src/destroy.ts +26 -8
- package/src/neon/project.ts +4 -5
- package/src/planetscale/api/client.gen.ts +2882 -0
- package/src/planetscale/api/index.ts +4 -0
- package/src/planetscale/api/types.gen.ts +13041 -0
- package/src/planetscale/branch.ts +152 -169
- package/src/planetscale/database.ts +195 -204
- package/src/planetscale/index.ts +1 -1
- package/src/planetscale/password.ts +86 -85
- package/src/planetscale/utils.ts +141 -122
- package/src/scope.ts +12 -3
- package/src/upstash/redis.ts +1 -1
- package/src/util/dedent.ts +33 -61
- package/src/util/idempotent-spawn.ts +23 -2
- package/src/util/xml.ts +1 -1
- package/templates/astro/alchemy.run.ts +1 -3
- package/templates/hono/alchemy.run.ts +0 -1
- package/templates/nuxt/alchemy.run.ts +1 -3
- package/templates/react-router/alchemy.run.ts +1 -3
- package/templates/rwsdk/alchemy.run.ts +0 -2
- package/templates/sveltekit/alchemy.run.ts +1 -3
- package/templates/tanstack-start/alchemy.run.ts +1 -3
- package/templates/typescript/alchemy.run.ts +0 -1
- package/templates/vite/alchemy.run.ts +0 -1
- package/workers/cloudflare-state-store.js +58 -58
- package/lib/cloudflare/bundle/externals.d.ts +0 -3
- package/lib/cloudflare/bundle/externals.d.ts.map +0 -1
- package/lib/cloudflare/bundle/externals.js +0 -35
- package/lib/cloudflare/bundle/externals.js.map +0 -1
- package/lib/cloudflare/bundle/plugin-compat-warning.d.ts +0 -10
- package/lib/cloudflare/bundle/plugin-compat-warning.d.ts.map +0 -1
- package/lib/cloudflare/bundle/plugin-compat-warning.js +0 -67
- package/lib/cloudflare/bundle/plugin-compat-warning.js.map +0 -1
- package/lib/planetscale/api.d.ts +0 -53
- package/lib/planetscale/api.d.ts.map +0 -1
- package/lib/planetscale/api.js +0 -84
- package/lib/planetscale/api.js.map +0 -1
- package/src/cloudflare/bundle/externals.ts +0 -36
- package/src/cloudflare/bundle/plugin-compat-warning.ts +0 -94
- package/src/planetscale/api.ts +0 -115
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Context } from "../context.ts";
|
|
2
2
|
import { Resource } from "../resource.ts";
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
3
|
+
import type { PlanetScaleProps } from "./api/client.gen.ts";
|
|
4
|
+
import { PlanetScaleClient } from "./api/client.gen.ts";
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
ensureProductionBranchClusterSize,
|
|
7
7
|
type PlanetScaleClusterSize,
|
|
8
8
|
waitForDatabaseReady,
|
|
9
9
|
} from "./utils.ts";
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
/**
|
|
12
12
|
* Properties for creating or updating a PlanetScale Database
|
|
13
13
|
*/
|
|
14
|
-
export interface DatabaseProps {
|
|
14
|
+
export interface DatabaseProps extends PlanetScaleProps {
|
|
15
15
|
/**
|
|
16
16
|
* The name of the database
|
|
17
17
|
*
|
|
@@ -24,11 +24,6 @@ export interface DatabaseProps {
|
|
|
24
24
|
*/
|
|
25
25
|
organizationId: string;
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* PlanetScale API token (overrides environment variable)
|
|
29
|
-
*/
|
|
30
|
-
apiKey?: Secret;
|
|
31
|
-
|
|
32
27
|
/**
|
|
33
28
|
* Whether to adopt the database if it already exists in Planetscale
|
|
34
29
|
*/
|
|
@@ -183,233 +178,229 @@ export const Database = Resource(
|
|
|
183
178
|
id: string,
|
|
184
179
|
props: DatabaseProps,
|
|
185
180
|
): Promise<Database> {
|
|
186
|
-
const
|
|
187
|
-
const apiKey =
|
|
188
|
-
props.apiKey?.unencrypted || process.env.PLANETSCALE_API_TOKEN;
|
|
189
|
-
if (!apiKey) {
|
|
190
|
-
throw new Error("PLANETSCALE_API_TOKEN environment variable is required");
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const api = new PlanetScaleApi({ apiKey });
|
|
181
|
+
const api = new PlanetScaleClient(props);
|
|
194
182
|
|
|
195
183
|
const databaseName =
|
|
196
184
|
props.name ?? this.output?.name ?? this.scope.createPhysicalName(id);
|
|
197
185
|
|
|
198
186
|
if (this.phase === "update" && this.output.name !== databaseName) {
|
|
199
|
-
await api.patch(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
187
|
+
await api.organizations.databases.patch({
|
|
188
|
+
path: {
|
|
189
|
+
organization: props.organizationId,
|
|
190
|
+
name: this.output.name,
|
|
191
|
+
},
|
|
192
|
+
body: { new_name: databaseName },
|
|
193
|
+
});
|
|
203
194
|
}
|
|
204
195
|
|
|
205
196
|
if (this.phase === "delete") {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
197
|
+
if (this.output?.name) {
|
|
198
|
+
const response = await api.organizations.databases.delete({
|
|
199
|
+
path: {
|
|
200
|
+
organization: props.organizationId,
|
|
201
|
+
name: this.output.name,
|
|
202
|
+
},
|
|
203
|
+
result: "full",
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (response.error && response.error.status !== 404) {
|
|
207
|
+
throw new Error(`Failed to delete database "${this.output.name}"`, {
|
|
208
|
+
cause: response.error,
|
|
209
|
+
});
|
|
217
210
|
}
|
|
218
|
-
} catch (error) {
|
|
219
|
-
console.error("Error deleting database:", error);
|
|
220
|
-
throw error;
|
|
221
211
|
}
|
|
222
212
|
return this.destroy();
|
|
223
213
|
}
|
|
224
214
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (props.defaultBranch && props.defaultBranch !== "main") {
|
|
238
|
-
const branchResponse = await api.get(
|
|
239
|
-
`/organizations/${props.organizationId}/databases/${databaseName}/branches/${props.defaultBranch}`,
|
|
240
|
-
);
|
|
241
|
-
if (!getData.ready) {
|
|
242
|
-
await waitForDatabaseReady(api, props.organizationId, databaseName);
|
|
243
|
-
}
|
|
244
|
-
if (!branchResponse.ok && branchResponse.status === 404) {
|
|
245
|
-
// Create the branch
|
|
246
|
-
const createBranchResponse = await api.post(
|
|
247
|
-
`/organizations/${props.organizationId}/databases/${databaseName}/branches`,
|
|
248
|
-
{
|
|
249
|
-
name: props.defaultBranch,
|
|
250
|
-
parent_branch: "main",
|
|
251
|
-
},
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
if (!createBranchResponse.ok) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Failed to create default branch: ${createBranchResponse.statusText} ${await createBranchResponse.text()}`,
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const updateResponse = await api.patch(
|
|
263
|
-
`/organizations/${props.organizationId}/databases/${databaseName}`,
|
|
264
|
-
{
|
|
265
|
-
automatic_migrations: props.automaticMigrations,
|
|
266
|
-
migration_framework: props.migrationFramework,
|
|
267
|
-
migration_table_name: props.migrationTableName,
|
|
268
|
-
require_approval_for_deploy: props.requireApprovalForDeploy,
|
|
269
|
-
restrict_branch_region: props.restrictBranchRegion,
|
|
270
|
-
allow_data_branching: props.allowDataBranching,
|
|
271
|
-
insights_raw_queries: props.insightsRawQueries,
|
|
272
|
-
production_branch_web_console: props.productionBranchWebConsole,
|
|
273
|
-
default_branch: props.defaultBranch,
|
|
274
|
-
},
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
if (!updateResponse.ok) {
|
|
278
|
-
throw new Error(
|
|
279
|
-
`Failed to update database: ${updateResponse.statusText} ${await updateResponse.text()}`,
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
await fixClusterSize(
|
|
284
|
-
api,
|
|
285
|
-
props.organizationId,
|
|
286
|
-
databaseName,
|
|
287
|
-
props.defaultBranch || "main",
|
|
288
|
-
props.clusterSize,
|
|
289
|
-
getData.ready,
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
const data = await updateResponse.json<any>();
|
|
293
|
-
return this({
|
|
294
|
-
...props,
|
|
295
|
-
id: data.id,
|
|
296
|
-
name: databaseName,
|
|
297
|
-
state: data.state,
|
|
298
|
-
defaultBranch: data.default_branch,
|
|
299
|
-
plan: data.plan,
|
|
300
|
-
createdAt: data.created_at,
|
|
301
|
-
updatedAt: data.updated_at,
|
|
302
|
-
htmlUrl: data.html_url,
|
|
215
|
+
// Check if database exists
|
|
216
|
+
const getResponse = await api.organizations.databases.get({
|
|
217
|
+
path: {
|
|
218
|
+
organization: props.organizationId,
|
|
219
|
+
name: databaseName,
|
|
220
|
+
},
|
|
221
|
+
result: "full",
|
|
222
|
+
});
|
|
223
|
+
if (this.phase === "update" || (props.adopt && getResponse.data)) {
|
|
224
|
+
if (!getResponse.data) {
|
|
225
|
+
throw new Error(`Database "${databaseName}" not found`, {
|
|
226
|
+
cause: getResponse.error,
|
|
303
227
|
});
|
|
304
228
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
229
|
+
// Update database settings
|
|
230
|
+
// If updating to a non-'main' default branch, create it first
|
|
231
|
+
if (props.defaultBranch && props.defaultBranch !== "main") {
|
|
232
|
+
const branchResponse = await api.organizations.databases.branches.get({
|
|
233
|
+
path: {
|
|
234
|
+
organization: props.organizationId,
|
|
235
|
+
database: databaseName,
|
|
236
|
+
name: props.defaultBranch,
|
|
237
|
+
},
|
|
238
|
+
result: "full",
|
|
239
|
+
});
|
|
240
|
+
if (!branchResponse.data) {
|
|
241
|
+
await waitForDatabaseReady(api, props.organizationId, databaseName);
|
|
242
|
+
}
|
|
243
|
+
if (branchResponse.error && branchResponse.error.status === 404) {
|
|
244
|
+
// Create the branch
|
|
245
|
+
await api.organizations.databases.branches.post({
|
|
246
|
+
path: {
|
|
247
|
+
organization: props.organizationId,
|
|
248
|
+
database: databaseName,
|
|
249
|
+
},
|
|
250
|
+
body: {
|
|
251
|
+
name: props.defaultBranch,
|
|
252
|
+
parent_branch: "main",
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
308
256
|
}
|
|
309
257
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
{
|
|
258
|
+
const updateResponse = await api.organizations.databases.patch({
|
|
259
|
+
path: {
|
|
260
|
+
organization: props.organizationId,
|
|
314
261
|
name: databaseName,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
allow_data_branching: props.allowDataBranching,
|
|
262
|
+
},
|
|
263
|
+
body: {
|
|
318
264
|
automatic_migrations: props.automaticMigrations,
|
|
265
|
+
migration_framework: props.migrationFramework,
|
|
266
|
+
migration_table_name: props.migrationTableName,
|
|
267
|
+
require_approval_for_deploy: props.requireApprovalForDeploy,
|
|
319
268
|
restrict_branch_region: props.restrictBranchRegion,
|
|
269
|
+
allow_data_branching: props.allowDataBranching,
|
|
320
270
|
insights_raw_queries: props.insightsRawQueries,
|
|
321
271
|
production_branch_web_console: props.productionBranchWebConsole,
|
|
322
|
-
|
|
323
|
-
migration_table_name: props.migrationTableName,
|
|
324
|
-
cluster_size: props.clusterSize,
|
|
272
|
+
default_branch: props.defaultBranch,
|
|
325
273
|
},
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
await ensureProductionBranchClusterSize(
|
|
277
|
+
api,
|
|
278
|
+
props.organizationId,
|
|
279
|
+
databaseName,
|
|
280
|
+
props.defaultBranch || "main",
|
|
281
|
+
props.clusterSize,
|
|
282
|
+
updateResponse.ready,
|
|
326
283
|
);
|
|
327
284
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
285
|
+
return this({
|
|
286
|
+
...props,
|
|
287
|
+
id: updateResponse.id,
|
|
288
|
+
name: databaseName,
|
|
289
|
+
state: updateResponse.state,
|
|
290
|
+
defaultBranch: updateResponse.default_branch,
|
|
291
|
+
plan: updateResponse.plan,
|
|
292
|
+
createdAt: updateResponse.created_at,
|
|
293
|
+
updatedAt: updateResponse.updated_at,
|
|
294
|
+
htmlUrl: updateResponse.html_url,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
333
297
|
|
|
334
|
-
|
|
298
|
+
if (getResponse.data) {
|
|
299
|
+
throw new Error(`Database with name "${databaseName}" already exists`);
|
|
300
|
+
}
|
|
335
301
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
302
|
+
// Create new database
|
|
303
|
+
let data = await api.organizations.databases.post({
|
|
304
|
+
path: {
|
|
305
|
+
organization: props.organizationId,
|
|
306
|
+
},
|
|
307
|
+
body: {
|
|
308
|
+
name: databaseName,
|
|
309
|
+
region: props.region?.slug,
|
|
310
|
+
kind: "mysql",
|
|
311
|
+
cluster_size: props.clusterSize,
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// These settings can't be set on creation, so we need to patch them after creation.
|
|
316
|
+
data = await api.organizations.databases.patch({
|
|
317
|
+
path: {
|
|
318
|
+
organization: props.organizationId,
|
|
319
|
+
name: databaseName,
|
|
320
|
+
},
|
|
321
|
+
body: {
|
|
322
|
+
require_approval_for_deploy: props.requireApprovalForDeploy,
|
|
323
|
+
allow_data_branching: props.allowDataBranching,
|
|
324
|
+
automatic_migrations: props.automaticMigrations,
|
|
325
|
+
restrict_branch_region: props.restrictBranchRegion,
|
|
326
|
+
insights_raw_queries: props.insightsRawQueries,
|
|
327
|
+
production_branch_web_console: props.productionBranchWebConsole,
|
|
328
|
+
migration_framework: props.migrationFramework,
|
|
329
|
+
migration_table_name: props.migrationTableName,
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// If a non-'main' default branch is specified, create it
|
|
334
|
+
if (props.defaultBranch && props.defaultBranch !== "main") {
|
|
335
|
+
await waitForDatabaseReady(api, props.organizationId, databaseName);
|
|
336
|
+
|
|
337
|
+
// Check if branch exists
|
|
338
|
+
const branchResponse = await api.organizations.databases.branches.get({
|
|
339
|
+
path: {
|
|
340
|
+
organization: props.organizationId,
|
|
341
|
+
database: databaseName,
|
|
342
|
+
name: props.defaultBranch,
|
|
343
|
+
},
|
|
344
|
+
result: "full",
|
|
345
|
+
});
|
|
339
346
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
347
|
+
if (branchResponse.error && branchResponse.error.status === 404) {
|
|
348
|
+
// Create the branch
|
|
349
|
+
await api.organizations.databases.branches.post({
|
|
350
|
+
path: {
|
|
351
|
+
organization: props.organizationId,
|
|
352
|
+
database: databaseName,
|
|
353
|
+
},
|
|
354
|
+
body: {
|
|
355
|
+
name: props.defaultBranch,
|
|
356
|
+
parent_branch: "main",
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
await ensureProductionBranchClusterSize(
|
|
361
|
+
api,
|
|
362
|
+
props.organizationId,
|
|
363
|
+
databaseName,
|
|
364
|
+
props.defaultBranch || "main",
|
|
365
|
+
props.clusterSize,
|
|
366
|
+
false,
|
|
343
367
|
);
|
|
344
368
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
{
|
|
350
|
-
name: props.defaultBranch,
|
|
351
|
-
parent_branch: "main",
|
|
352
|
-
},
|
|
353
|
-
);
|
|
354
|
-
|
|
355
|
-
if (!createBranchResponse.ok) {
|
|
356
|
-
throw new Error(
|
|
357
|
-
`Failed to create default branch: ${createBranchResponse.statusText} ${await createBranchResponse.text()}`,
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
await fixClusterSize(
|
|
362
|
-
api,
|
|
363
|
-
props.organizationId,
|
|
364
|
-
databaseName,
|
|
365
|
-
props.defaultBranch || "main",
|
|
366
|
-
props.clusterSize,
|
|
367
|
-
false,
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
// Update database to use new branch as default
|
|
371
|
-
const updateResponse = await api.patch(
|
|
372
|
-
`/organizations/${props.organizationId}/databases/${databaseName}`,
|
|
373
|
-
{
|
|
374
|
-
default_branch: props.defaultBranch,
|
|
375
|
-
},
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
if (!updateResponse.ok) {
|
|
379
|
-
throw new Error(
|
|
380
|
-
`Failed to set default branch: ${updateResponse.statusText} ${await updateResponse.text()}`,
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const updatedData = await updateResponse.json<any>();
|
|
385
|
-
return this({
|
|
386
|
-
...props,
|
|
387
|
-
id: data.id,
|
|
369
|
+
// Update database to use new branch as default
|
|
370
|
+
const updatedData = await api.organizations.databases.patch({
|
|
371
|
+
path: {
|
|
372
|
+
organization: props.organizationId,
|
|
388
373
|
name: databaseName,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
htmlUrl: updatedData.html_url,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
}
|
|
374
|
+
},
|
|
375
|
+
body: {
|
|
376
|
+
default_branch: props.defaultBranch,
|
|
377
|
+
},
|
|
378
|
+
});
|
|
398
379
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
console.error("Error managing database:", error);
|
|
412
|
-
throw error;
|
|
380
|
+
return this({
|
|
381
|
+
...props,
|
|
382
|
+
id: data.id,
|
|
383
|
+
name: databaseName,
|
|
384
|
+
state: updatedData.state,
|
|
385
|
+
defaultBranch: updatedData.default_branch,
|
|
386
|
+
plan: updatedData.plan,
|
|
387
|
+
createdAt: updatedData.created_at,
|
|
388
|
+
updatedAt: updatedData.updated_at,
|
|
389
|
+
htmlUrl: updatedData.html_url,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
413
392
|
}
|
|
393
|
+
|
|
394
|
+
return this({
|
|
395
|
+
...props,
|
|
396
|
+
id: data.id,
|
|
397
|
+
name: databaseName,
|
|
398
|
+
state: data.state,
|
|
399
|
+
defaultBranch: data.default_branch || "main",
|
|
400
|
+
plan: data.plan,
|
|
401
|
+
createdAt: data.created_at,
|
|
402
|
+
updatedAt: data.updated_at,
|
|
403
|
+
htmlUrl: data.html_url,
|
|
404
|
+
});
|
|
414
405
|
},
|
|
415
406
|
);
|
package/src/planetscale/index.ts
CHANGED