@agentic-kit/db-tools 0.12.46 → 0.13.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/README.md +18 -4
- package/access/findings.d.ts +93 -0
- package/access/findings.js +434 -0
- package/access/index.d.ts +5 -0
- package/access/index.js +27 -0
- package/access/policies.d.ts +142 -0
- package/access/policies.js +338 -0
- package/access/provisioning.d.ts +121 -0
- package/access/provisioning.js +381 -0
- package/access/rule-check.d.ts +52 -0
- package/access/rule-check.js +307 -0
- package/access/words.d.ts +38 -0
- package/access/words.js +530 -0
- package/app-workspace.d.ts +1 -0
- package/app-workspace.js +7 -9
- package/blueprint/blueprint-defaults.d.ts +9 -0
- package/blueprint/blueprint-defaults.js +77 -0
- package/blueprint/blueprint-schema.d.ts +68 -0
- package/blueprint/blueprint-schema.js +139 -0
- package/blueprint/field-type.d.ts +4 -0
- package/blueprint/field-type.js +100 -0
- package/blueprint/internal-policies.d.ts +1 -0
- package/blueprint/internal-policies.js +10 -0
- package/blueprint-construction.d.ts +10 -6
- package/blueprint-construction.js +34 -25
- package/context.d.ts +15 -0
- package/context.js +132 -69
- package/db-probe.d.ts +1 -1
- package/db-probe.js +19 -4
- package/esm/access/findings.d.ts +93 -0
- package/esm/access/findings.js +428 -0
- package/esm/access/index.d.ts +5 -0
- package/esm/access/index.js +5 -0
- package/esm/access/policies.d.ts +142 -0
- package/esm/access/policies.js +315 -0
- package/esm/access/provisioning.d.ts +121 -0
- package/esm/access/provisioning.js +375 -0
- package/esm/access/rule-check.d.ts +52 -0
- package/esm/access/rule-check.js +297 -0
- package/esm/access/words.d.ts +38 -0
- package/esm/access/words.js +524 -0
- package/esm/app-workspace.d.ts +1 -0
- package/esm/app-workspace.js +7 -10
- package/esm/blueprint/blueprint-defaults.d.ts +9 -0
- package/esm/blueprint/blueprint-defaults.js +74 -0
- package/esm/blueprint/blueprint-schema.d.ts +68 -0
- package/esm/blueprint/blueprint-schema.js +134 -0
- package/esm/blueprint/field-type.d.ts +4 -0
- package/esm/blueprint/field-type.js +95 -0
- package/esm/blueprint/internal-policies.d.ts +1 -0
- package/esm/blueprint/internal-policies.js +7 -0
- package/esm/blueprint-construction.d.ts +10 -6
- package/esm/blueprint-construction.js +32 -24
- package/esm/context.d.ts +15 -0
- package/esm/context.js +133 -70
- package/esm/db-probe.d.ts +1 -1
- package/esm/db-probe.js +21 -6
- package/esm/failure.d.ts +89 -0
- package/esm/failure.js +362 -0
- package/esm/gate.d.ts +6 -4
- package/esm/gate.js +42 -14
- package/esm/graphql-http.d.ts +27 -6
- package/esm/graphql-http.js +96 -24
- package/esm/host.d.ts +33 -8
- package/esm/host.js +42 -2
- package/esm/index.d.ts +22 -12
- package/esm/index.js +21 -39
- package/esm/provision-database/env-file.d.ts +7 -0
- package/esm/provision-database/env-file.js +30 -0
- package/esm/provision-database/preset-match.js +1 -2
- package/esm/provision-database/provision.d.ts +21 -4
- package/esm/provision-database/provision.js +330 -85
- package/esm/provision-database/request-database.d.ts +22 -3
- package/esm/provision-database/request-database.js +46 -13
- package/esm/ready.d.ts +20 -0
- package/esm/ready.js +45 -0
- package/esm/run-codegen/barrels.js +1 -1
- package/esm/run-codegen/endpoints.js +5 -6
- package/esm/schema-model/normalize.js +1 -1
- package/esm/schema-model.js +4 -5
- package/esm/schema-resolve.d.ts +50 -0
- package/esm/schema-resolve.js +200 -14
- package/esm/table-access.d.ts +116 -0
- package/esm/table-access.js +418 -0
- package/esm/tools/access.d.ts +218 -0
- package/esm/tools/access.js +651 -0
- package/esm/tools/add-policies.d.ts +44 -12
- package/esm/tools/add-policies.js +84 -84
- package/esm/tools/add-records.d.ts +23 -2
- package/esm/tools/add-records.js +113 -75
- package/esm/tools/add-relation-schema.d.ts +5 -5
- package/esm/tools/add-relation-schema.js +13 -14
- package/esm/tools/add-relation.d.ts +11 -2
- package/esm/tools/add-relation.js +68 -31
- package/esm/tools/create-api-key.d.ts +18 -4
- package/esm/tools/create-api-key.js +105 -54
- package/esm/tools/describe-schema.d.ts +5 -7
- package/esm/tools/describe-schema.js +41 -118
- package/esm/tools/entity-types.d.ts +54 -0
- package/esm/tools/entity-types.js +233 -0
- package/esm/tools/index.d.ts +26 -0
- package/esm/tools/index.js +151 -0
- package/esm/tools/mutations.d.ts +36 -7
- package/esm/tools/mutations.js +245 -99
- package/esm/tools/provision-blueprint.d.ts +25 -1
- package/esm/tools/provision-blueprint.js +184 -42
- package/esm/tools/provision-database.d.ts +7 -5
- package/esm/tools/provision-database.js +31 -17
- package/esm/tools/run-codegen.d.ts +27 -4
- package/esm/tools/run-codegen.js +143 -76
- package/esm/tools/templates.d.ts +30 -7
- package/esm/tools/templates.js +166 -95
- package/failure.d.ts +89 -0
- package/failure.js +375 -0
- package/gate.d.ts +6 -4
- package/gate.js +41 -13
- package/graphql-http.d.ts +27 -6
- package/graphql-http.js +105 -25
- package/host.d.ts +33 -8
- package/host.js +45 -2
- package/index.d.ts +22 -12
- package/index.js +86 -43
- package/package.json +6 -5
- package/provision-database/env-file.d.ts +7 -0
- package/provision-database/env-file.js +32 -1
- package/provision-database/preset-match.js +1 -2
- package/provision-database/provision.d.ts +21 -4
- package/provision-database/provision.js +327 -81
- package/provision-database/request-database.d.ts +22 -3
- package/provision-database/request-database.js +49 -14
- package/ready.d.ts +20 -0
- package/ready.js +52 -0
- package/run-codegen/barrels.js +1 -1
- package/run-codegen/endpoints.js +5 -6
- package/schema-model/normalize.js +4 -4
- package/schema-model.js +4 -5
- package/schema-resolve.d.ts +50 -0
- package/schema-resolve.js +209 -14
- package/table-access.d.ts +116 -0
- package/table-access.js +437 -0
- package/tools/access.d.ts +218 -0
- package/tools/access.js +669 -0
- package/tools/add-policies.d.ts +44 -12
- package/tools/add-policies.js +86 -84
- package/tools/add-records.d.ts +23 -2
- package/tools/add-records.js +113 -74
- package/tools/add-relation-schema.d.ts +5 -5
- package/tools/add-relation-schema.js +13 -14
- package/tools/add-relation.d.ts +11 -2
- package/tools/add-relation.js +69 -31
- package/tools/create-api-key.d.ts +18 -4
- package/tools/create-api-key.js +104 -53
- package/tools/describe-schema.d.ts +5 -7
- package/tools/describe-schema.js +40 -117
- package/tools/entity-types.d.ts +54 -0
- package/tools/entity-types.js +240 -0
- package/tools/index.d.ts +26 -0
- package/tools/index.js +154 -0
- package/tools/mutations.d.ts +36 -7
- package/tools/mutations.js +252 -101
- package/tools/provision-blueprint.d.ts +25 -1
- package/tools/provision-blueprint.js +186 -43
- package/tools/provision-database.d.ts +7 -5
- package/tools/provision-database.js +33 -18
- package/tools/run-codegen.d.ts +27 -4
- package/tools/run-codegen.js +141 -73
- package/tools/templates.d.ts +30 -7
- package/tools/templates.js +167 -94
- package/esm/policy/add-policies-to-table.d.ts +0 -26
- package/esm/policy/add-policies-to-table.js +0 -66
- package/esm/policy/provision-helpers.d.ts +0 -38
- package/esm/policy/provision-helpers.js +0 -50
- package/esm/tools/manage-entity-types.d.ts +0 -40
- package/esm/tools/manage-entity-types.js +0 -201
- package/policy/add-policies-to-table.d.ts +0 -26
- package/policy/add-policies-to-table.js +0 -71
- package/policy/provision-helpers.d.ts +0 -38
- package/policy/provision-helpers.js +0 -58
- package/tools/manage-entity-types.d.ts +0 -40
- package/tools/manage-entity-types.js +0 -206
|
@@ -14,12 +14,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.boundDatabaseId = boundDatabaseId;
|
|
17
|
+
exports.provisionDatabaseReady = provisionDatabaseReady;
|
|
17
18
|
exports.provisionDatabase = provisionDatabase;
|
|
18
19
|
exports.provisionFromTool = provisionFromTool;
|
|
20
|
+
const node_fs_1 = require("node:fs");
|
|
19
21
|
const promises_1 = require("node:fs/promises");
|
|
20
22
|
const node_path_1 = __importDefault(require("node:path"));
|
|
21
23
|
const app_workspace_1 = require("../app-workspace");
|
|
22
24
|
const db_probe_1 = require("../db-probe");
|
|
25
|
+
const failure_1 = require("../failure");
|
|
26
|
+
const graphql_http_1 = require("../graphql-http");
|
|
23
27
|
const host_1 = require("../host");
|
|
24
28
|
const credential_1 = require("./credential");
|
|
25
29
|
const env_file_1 = require("./env-file");
|
|
@@ -28,10 +32,20 @@ const pending_ticket_1 = require("./pending-ticket");
|
|
|
28
32
|
const preset_match_1 = require("./preset-match");
|
|
29
33
|
const request_database_1 = require("./request-database");
|
|
30
34
|
const resolve_1 = require("./resolve");
|
|
31
|
-
function
|
|
32
|
-
|
|
35
|
+
function refuse(code, why, extra = {}) {
|
|
36
|
+
const failure = { ...why, code };
|
|
37
|
+
return { ...extra, success: false, message: (0, failure_1.failureText)(failure), code, failure };
|
|
38
|
+
}
|
|
39
|
+
function withoutFailure({ failure: _failure, ...details }) {
|
|
40
|
+
return details;
|
|
41
|
+
}
|
|
42
|
+
// A probe the backend could not answer: a rejected account credential needs a
|
|
43
|
+
// sign-in, which the probe's detail already asks for; anything else, a retry.
|
|
44
|
+
function unanswered(probe, message, hint, extra = {}) {
|
|
45
|
+
return probe.cause === 'auth'
|
|
46
|
+
? refuse('signed-out', { message }, extra)
|
|
47
|
+
: refuse('backend-unreachable', { message, hint, retryable: true }, extra);
|
|
33
48
|
}
|
|
34
|
-
const errorText = (err) => (err instanceof Error ? err.message : String(err));
|
|
35
49
|
const today = () => new Date().toISOString().slice(0, 10);
|
|
36
50
|
const noop = () => undefined;
|
|
37
51
|
async function readText(file) {
|
|
@@ -48,13 +62,86 @@ async function readText(file) {
|
|
|
48
62
|
async function updateEnvFile(envPath, edit) {
|
|
49
63
|
await (0, promises_1.writeFile)(envPath, edit(await readText(envPath)));
|
|
50
64
|
}
|
|
51
|
-
/**
|
|
65
|
+
/** A project's `.env`, with each binding value checked: one that is not of its form is never used, sent or shown. */
|
|
66
|
+
async function readBinding(envPath) {
|
|
67
|
+
const env = (0, env_file_1.readEnv)(await readText(envPath));
|
|
68
|
+
const invalid = (0, env_file_1.invalidBindingKeys)(env);
|
|
69
|
+
return invalid.length ? { kind: 'failed', failure: (0, failure_1.invalidBinding)(invalid) } : { kind: 'ok', value: env };
|
|
70
|
+
}
|
|
71
|
+
/** The DATABASE_ID in a project's `.env`, if it has one of the form a database id takes. */
|
|
52
72
|
async function boundDatabaseId(cwd) {
|
|
53
|
-
|
|
73
|
+
const binding = await boundDatabase(cwd);
|
|
74
|
+
return binding.kind === 'ok' ? binding.value?.id : undefined;
|
|
75
|
+
}
|
|
76
|
+
/** The database the `.env` of `cwd` binds, as a plan names it. */
|
|
77
|
+
async function boundDatabase(cwd) {
|
|
78
|
+
const binding = await readBinding(node_path_1.default.join(cwd, '.env'));
|
|
79
|
+
if (binding.kind === 'failed')
|
|
80
|
+
return binding;
|
|
81
|
+
const env = binding.value;
|
|
82
|
+
return { kind: 'ok', value: env.DATABASE_ID ? { name: env.DATABASE_NAME ?? '', id: env.DATABASE_ID } : undefined };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The backend and the account a provision runs with, or why it cannot run.
|
|
86
|
+
* The host's backend config is the only endpoint source: the account bearer
|
|
87
|
+
* provisions with it, so an ambient env var or a guessed default must never
|
|
88
|
+
* redirect it. Every project provisions UNDER the account (requestDatabase
|
|
89
|
+
* owns the database to the JWT user).
|
|
90
|
+
*/
|
|
91
|
+
async function provisionAccess(host) {
|
|
92
|
+
const backendRead = (0, host_1.readBackendConfig)(host);
|
|
93
|
+
if (backendRead.kind === 'failed')
|
|
94
|
+
return { kind: 'failed', failure: { ...backendRead.failure, code: 'no-backend' } };
|
|
95
|
+
const apiEndpoint = backendRead.value?.apiEndpoint;
|
|
96
|
+
const modulesEndpoint = backendRead.value?.modulesEndpoint;
|
|
97
|
+
if (!apiEndpoint || !modulesEndpoint) {
|
|
98
|
+
const noBackend = (0, failure_1.noBackendFailure)(host.signInHint);
|
|
99
|
+
return { kind: 'failed', failure: { ...noBackend, message: `Cannot provision a database: ${noBackend.message}` } };
|
|
100
|
+
}
|
|
101
|
+
const accountRead = await (0, host_1.readAccount)(host);
|
|
102
|
+
if (accountRead.kind === 'failed')
|
|
103
|
+
return { kind: 'failed', failure: { ...accountRead.failure, code: 'signed-out' } };
|
|
104
|
+
const credential = (0, credential_1.selectProvisionCredential)(accountRead.value, host.signInHint);
|
|
105
|
+
if (credential.mode === 'error') {
|
|
106
|
+
return { kind: 'failed', failure: { code: 'signed-out', message: `Cannot provision a database: ${credential.reason}` } };
|
|
107
|
+
}
|
|
108
|
+
const account = accountRead.value;
|
|
109
|
+
return {
|
|
110
|
+
kind: 'ok',
|
|
111
|
+
value: { apiEndpoint, modulesEndpoint, credential, ...(account?.email ? { email: account.email } : {}), ...(account?.agent ? { agent: account.agent } : {}) },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* What provision_database and replace_database check before they change
|
|
116
|
+
* anything: a backend and an account to provision under, and a binding whose
|
|
117
|
+
* values are of their form. They act on no bound database; a replace names
|
|
118
|
+
* the one the directory leaves.
|
|
119
|
+
*/
|
|
120
|
+
async function provisionDatabaseReady(replace, cwd) {
|
|
121
|
+
const access = await provisionAccess((0, host_1.getHost)());
|
|
122
|
+
if (access.kind === 'failed')
|
|
123
|
+
return access;
|
|
124
|
+
const bound = await boundDatabase(cwd);
|
|
125
|
+
if (bound.kind === 'failed')
|
|
126
|
+
return bound;
|
|
127
|
+
const replaces = replace ? bound.value : undefined;
|
|
128
|
+
return {
|
|
129
|
+
kind: 'ok',
|
|
130
|
+
value: {
|
|
131
|
+
kind: 'account',
|
|
132
|
+
apiEndpoint: access.value.apiEndpoint,
|
|
133
|
+
account: {
|
|
134
|
+
userId: access.value.credential.ownerId,
|
|
135
|
+
...(access.value.email ? { email: access.value.email } : {}),
|
|
136
|
+
...(access.value.agent ? { agent: access.value.agent } : {}),
|
|
137
|
+
},
|
|
138
|
+
...(replaces ? { replaces } : {}),
|
|
139
|
+
},
|
|
140
|
+
};
|
|
54
141
|
}
|
|
55
142
|
// The per-DB endpoints are subdomain.<domain>; the provisioning domain is the api
|
|
56
|
-
// endpoint's host minus its first label (api.
|
|
57
|
-
//
|
|
143
|
+
// endpoint's host minus its first label (api.example.com -> example.com), so
|
|
144
|
+
// every backend provisions under its own domain.
|
|
58
145
|
function provisionDomain(apiEndpoint) {
|
|
59
146
|
try {
|
|
60
147
|
const { hostname } = new URL(apiEndpoint);
|
|
@@ -77,8 +164,18 @@ function pollDeadline(ms) {
|
|
|
77
164
|
const projectLocks = new Map();
|
|
78
165
|
// One provision per project at a time: a second call waits, then sees what
|
|
79
166
|
// the first one left (a binding, a recorded ticket) instead of racing it.
|
|
167
|
+
// The key is resolved synchronously, so a call takes its place in the queue
|
|
168
|
+
// before it yields and calls queue in call order.
|
|
169
|
+
function lockKey(cwd) {
|
|
170
|
+
try {
|
|
171
|
+
return (0, node_fs_1.realpathSync)(cwd);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return node_path_1.default.resolve(cwd);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
80
177
|
async function withProjectLock(cwd, fn) {
|
|
81
|
-
const key =
|
|
178
|
+
const key = lockKey(cwd);
|
|
82
179
|
const previous = projectLocks.get(key) ?? Promise.resolve();
|
|
83
180
|
let release = noop;
|
|
84
181
|
const done = new Promise((resolve) => (release = resolve));
|
|
@@ -99,40 +196,34 @@ async function withProjectLock(cwd, fn) {
|
|
|
99
196
|
* entry point: replace mode refuses a live binding here, and `abandonPending`
|
|
100
197
|
* and `adopt` are honoured.
|
|
101
198
|
*/
|
|
102
|
-
function provisionDatabase(input, ctx, exec = app_workspace_1.run) {
|
|
103
|
-
return withProjectLock(ctx.cwd, () => provision(input, ctx.cwd, exec, false));
|
|
199
|
+
async function provisionDatabase(input, ctx, exec = app_workspace_1.run) {
|
|
200
|
+
return withoutFailure(await withProjectLock(ctx.cwd, () => provision(input, ctx.cwd, exec, false)));
|
|
104
201
|
}
|
|
105
202
|
/**
|
|
106
|
-
* The
|
|
203
|
+
* The entry point of provision_database and replace_database: a replace may
|
|
107
204
|
* replace a live binding (a clean rebuild), unless the host turned tool
|
|
108
205
|
* reprovisioning off.
|
|
109
206
|
*/
|
|
110
|
-
function provisionFromTool(input, ctx, exec = app_workspace_1.run) {
|
|
111
|
-
|
|
207
|
+
async function provisionFromTool(input, ctx, exec = app_workspace_1.run) {
|
|
208
|
+
const outcome = await withProjectLock(ctx.cwd, () => provision(input, ctx.cwd, exec, true));
|
|
209
|
+
return { details: withoutFailure(outcome), ...(outcome.failure ? { failure: outcome.failure } : {}) };
|
|
112
210
|
}
|
|
113
211
|
async function provision(input, cwd, exec, viaTool) {
|
|
114
212
|
const name = input.databaseName?.trim();
|
|
115
213
|
if (!name)
|
|
116
|
-
return
|
|
117
|
-
// The host's backend config is the only endpoint source: the account bearer
|
|
118
|
-
// provisions with it, so an ambient env var or a guessed default must never
|
|
119
|
-
// redirect it.
|
|
214
|
+
return refuse('invalid-input', { message: 'The database needs a name.' });
|
|
120
215
|
const host = (0, host_1.getHost)();
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return failure('failed', `Cannot provision a database: ${(0, host_1.noBackendReason)(host.signInHint)}`);
|
|
126
|
-
}
|
|
127
|
-
// Every project provisions UNDER the account (requestDatabase owns the
|
|
128
|
-
// database to the JWT user). The account bearer authenticates the mutation
|
|
129
|
-
// and the probes.
|
|
130
|
-
const credential = (0, credential_1.selectProvisionCredential)(host.account(), host.signInHint);
|
|
131
|
-
if (credential.mode === 'error') {
|
|
132
|
-
return failure('signed-out', `Cannot provision a database: ${credential.reason}`);
|
|
216
|
+
const access = await provisionAccess(host);
|
|
217
|
+
if (access.kind === 'failed') {
|
|
218
|
+
const { code, ...why } = access.failure;
|
|
219
|
+
return refuse(code, why);
|
|
133
220
|
}
|
|
221
|
+
const { apiEndpoint, modulesEndpoint, credential } = access.value;
|
|
134
222
|
const envPath = node_path_1.default.join(cwd, '.env');
|
|
135
|
-
const
|
|
223
|
+
const binding = await readBinding(envPath);
|
|
224
|
+
if (binding.kind === 'failed')
|
|
225
|
+
return refuse('missing-credentials', binding.failure);
|
|
226
|
+
const env = binding.value;
|
|
136
227
|
const bound = env.DATABASE_ID || undefined;
|
|
137
228
|
const r = {
|
|
138
229
|
host,
|
|
@@ -162,7 +253,7 @@ async function provision(input, cwd, exec, viaTool) {
|
|
|
162
253
|
}
|
|
163
254
|
if (input.adopt) {
|
|
164
255
|
const prewarm = startPrewarm(r, exec);
|
|
165
|
-
return bindDatabase(r, { databaseId: input.adopt, replaced, adopted: true }, prewarm);
|
|
256
|
+
return afterPrewarm(await bindDatabase(r, { databaseId: input.adopt, replaced, adopted: true }, prewarm), prewarm);
|
|
166
257
|
}
|
|
167
258
|
return requestAndBind(r, input, env, replaced, exec);
|
|
168
259
|
}
|
|
@@ -170,19 +261,30 @@ async function provision(input, cwd, exec, viaTool) {
|
|
|
170
261
|
async function keepBinding(r, env, bound, adopt) {
|
|
171
262
|
const probe = await r.probe(bound);
|
|
172
263
|
if (probe.status === 'unreachable') {
|
|
173
|
-
return
|
|
264
|
+
return unanswered(probe, `Cannot verify the existing database binding (DATABASE_ID=${bound}): ${probe.detail}.`, "Retry once the backend answers; don't reprovision on an unreachable backend.", { databaseId: bound });
|
|
174
265
|
}
|
|
175
266
|
if (probe.status === 'missing') {
|
|
176
|
-
return
|
|
267
|
+
return refuse('db-missing', {
|
|
268
|
+
message: `Project carries a binding (DATABASE_ID=${bound}) but that database no longer exists on this backend, or this account lost access to it.`,
|
|
269
|
+
hint: (0, host_1.reprovisionAdvice)(r.host),
|
|
270
|
+
...(0, host_1.replaceCall)(r.host),
|
|
271
|
+
}, { databaseId: bound });
|
|
177
272
|
}
|
|
178
273
|
if (probe.ownerId && probe.ownerId !== r.ownerId) {
|
|
179
|
-
return
|
|
274
|
+
return refuse('account-mismatch', {
|
|
275
|
+
message: `Project carries a binding (DATABASE_ID=${bound}) but that database was provisioned under a different account than the one signed in.`,
|
|
276
|
+
hint: (0, host_1.reprovisionAdvice)(r.host),
|
|
277
|
+
...(0, host_1.replaceCall)(r.host),
|
|
278
|
+
}, { databaseId: bound });
|
|
180
279
|
}
|
|
181
280
|
if (probe.status === 'suspended') {
|
|
182
|
-
return
|
|
281
|
+
return refuse('db-suspended', { message: suspendedText(bound, probe) }, { databaseId: bound });
|
|
183
282
|
}
|
|
184
283
|
if (adopt && adopt !== bound) {
|
|
185
|
-
return
|
|
284
|
+
return refuse('binding-live', {
|
|
285
|
+
message: `The project is bound to a live database (DATABASE_ID=${bound}); adopt binds only an unbound project.`,
|
|
286
|
+
hint: 'Use replace mode to swap it.',
|
|
287
|
+
}, { databaseId: bound });
|
|
186
288
|
}
|
|
187
289
|
// Heal stale endpoint pins and missing binding keys on the skip path.
|
|
188
290
|
const databaseName = env.DATABASE_NAME || probe.name || '';
|
|
@@ -217,10 +319,10 @@ async function keepBinding(r, env, bound, adopt) {
|
|
|
217
319
|
note = ` Refreshed in .env: ${keys}.`;
|
|
218
320
|
}
|
|
219
321
|
catch (err) {
|
|
220
|
-
note = ` Could not refresh ${keys} in .env: ${
|
|
322
|
+
note = ` Could not refresh ${keys} in .env: ${(0, graphql_http_1.thrownText)(err)}.`;
|
|
221
323
|
}
|
|
222
324
|
}
|
|
223
|
-
const advice = r.host.toolReprovision === false ? '' : '
|
|
325
|
+
const advice = r.host.toolReprovision === false ? '' : ' Replacing it with a new database is a separate change, only for an explicit clean rebuild.';
|
|
224
326
|
return {
|
|
225
327
|
success: true,
|
|
226
328
|
message: `Project already provisioned (DATABASE_ID=${bound}) and the database is live under this account. Skipping.${advice}${note}`,
|
|
@@ -237,24 +339,30 @@ function suspendedText(databaseId, probe) {
|
|
|
237
339
|
// ---- replace: compare and swap -------------------------------------------
|
|
238
340
|
async function checkReplace(r, input, bound) {
|
|
239
341
|
if (r.viaTool && r.host.toolReprovision === false) {
|
|
240
|
-
return
|
|
342
|
+
return refuse('reprovision-not-allowed', {
|
|
343
|
+
message: "This project's database is not replaced here: the app replaces a database only after the user approves it.",
|
|
344
|
+
hint: (0, host_1.reprovisionAdvice)(r.host),
|
|
345
|
+
});
|
|
241
346
|
}
|
|
242
347
|
const expected = input.replaces === undefined ? bound : input.replaces || undefined;
|
|
243
348
|
if ((expected ?? '') !== (bound ?? '')) {
|
|
244
|
-
return
|
|
349
|
+
return refuse('binding-changed', {
|
|
350
|
+
message: `The project's binding changed (DATABASE_ID is ${bound ?? 'unset'}, expected ${expected ?? 'unset'}), so nothing was replaced.`,
|
|
351
|
+
}, { databaseId: bound });
|
|
245
352
|
}
|
|
246
353
|
if (!bound)
|
|
247
354
|
return null;
|
|
248
355
|
const probe = await r.probe(bound);
|
|
249
356
|
if (probe.status === 'unreachable') {
|
|
250
|
-
return
|
|
357
|
+
return unanswered(probe, `Cannot verify the binding being replaced (DATABASE_ID=${bound}): ${probe.detail}.`, 'Retry once the backend answers.', { databaseId: bound });
|
|
358
|
+
}
|
|
359
|
+
if (probe.status === 'suspended') {
|
|
360
|
+
return refuse('db-suspended', { message: suspendedText(bound, probe) }, { databaseId: bound });
|
|
251
361
|
}
|
|
252
|
-
if (probe.status === 'suspended')
|
|
253
|
-
return failure('db-suspended', suspendedText(bound, probe), { databaseId: bound });
|
|
254
362
|
// A missing or foreign-owned binding is replaced; a live one of this account
|
|
255
363
|
// only through the tool's explicit rebuild.
|
|
256
364
|
if (probe.status === 'found' && (!probe.ownerId || probe.ownerId === r.ownerId) && !r.viaTool) {
|
|
257
|
-
return
|
|
365
|
+
return refuse('binding-live', { message: `The bound database (DATABASE_ID=${bound}) is live under this account, so it wasn't replaced.` }, { databaseId: bound });
|
|
258
366
|
}
|
|
259
367
|
return null;
|
|
260
368
|
}
|
|
@@ -267,13 +375,26 @@ async function findInFlight(r, skip) {
|
|
|
267
375
|
return { inFlight: tickets.filter((t) => t.id && !skip.has(t.id) && (0, request_database_1.isTicketInFlight)(t)) };
|
|
268
376
|
}
|
|
269
377
|
catch (err) {
|
|
378
|
+
if ((0, graphql_http_1.answersSignedOut)(err)) {
|
|
379
|
+
return {
|
|
380
|
+
inFlight: [],
|
|
381
|
+
refusal: refuse('signed-out', {
|
|
382
|
+
message: `The backend did not accept the account credential while this call checked for a provision of "${r.name}" already in progress. Nothing was requested.`,
|
|
383
|
+
hint: r.host.signInHint ?? 'Sign in again, then call again.',
|
|
384
|
+
}),
|
|
385
|
+
};
|
|
386
|
+
}
|
|
270
387
|
if ((0, request_database_1.isTransientProvisionError)(err)) {
|
|
271
388
|
return {
|
|
272
389
|
inFlight: [],
|
|
273
|
-
refusal:
|
|
390
|
+
refusal: refuse('backend-unreachable', {
|
|
391
|
+
message: `Could not check the backend for a provision of "${r.name}" already in progress (${(0, graphql_http_1.thrownText)(err)}). Nothing was requested.`,
|
|
392
|
+
hint: 'Retry once the backend answers.',
|
|
393
|
+
retryable: true,
|
|
394
|
+
}),
|
|
274
395
|
};
|
|
275
396
|
}
|
|
276
|
-
return { inFlight: [], problem:
|
|
397
|
+
return { inFlight: [], problem: (0, graphql_http_1.thrownText)(err) };
|
|
277
398
|
}
|
|
278
399
|
}
|
|
279
400
|
const ticketOf = (r, ticket) => ({
|
|
@@ -283,12 +404,25 @@ const ticketOf = (r, ticket) => ({
|
|
|
283
404
|
userId: r.ownerId,
|
|
284
405
|
attempts: 0,
|
|
285
406
|
});
|
|
407
|
+
// The packages/app scaffold + install don't need the database, so they run
|
|
408
|
+
// while the backend builds it. Best-effort: run_codegen re-runs the same
|
|
409
|
+
// idempotent steps. A pending call leaves it running; a retry joins that same
|
|
410
|
+
// run rather than starting a second install.
|
|
286
411
|
function startPrewarm(r, exec) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
412
|
+
if (r.host.prewarmApp === false)
|
|
413
|
+
return Promise.resolve({ ok: false, out: 'The host prepares packages/app itself.' });
|
|
414
|
+
return (0, app_workspace_1.prewarmAppWorkspace)(r.cwd, exec).catch((err) => ({ ok: false, out: (0, graphql_http_1.thrownText)(err) }));
|
|
415
|
+
}
|
|
416
|
+
// The prewarm runs whether or not a database comes of the call, so a call that
|
|
417
|
+
// fails after it started waits for it and says what it left in packages/app.
|
|
418
|
+
async function afterPrewarm(outcome, prewarm) {
|
|
419
|
+
if (outcome.success || outcome.pending || !outcome.failure || !(await prewarm).ok)
|
|
420
|
+
return outcome;
|
|
421
|
+
const failure = {
|
|
422
|
+
...outcome.failure,
|
|
423
|
+
message: `${outcome.failure.message.replace(/\.?$/, '.')} packages/app is ready for the next attempt.`,
|
|
424
|
+
};
|
|
425
|
+
return { ...outcome, failure, message: (0, failure_1.failureText)(failure), appWorkspacePrepared: true };
|
|
292
426
|
}
|
|
293
427
|
async function requestAndBind(r, input, env, replaced, exec) {
|
|
294
428
|
const abandoned = (0, pending_ticket_1.abandonedTickets)(env);
|
|
@@ -310,7 +444,11 @@ async function requestAndBind(r, input, env, replaced, exec) {
|
|
|
310
444
|
await abandon([recorded.ticketId]);
|
|
311
445
|
}
|
|
312
446
|
else if (recorded.databaseName !== r.name) {
|
|
313
|
-
return
|
|
447
|
+
return refuse('pending-other', {
|
|
448
|
+
message: `A provision of "${recorded.databaseName}" (ticket ${recorded.ticketId}) is still recorded for this project.`,
|
|
449
|
+
hint: `Call again with the name "${recorded.databaseName}" to finish it; another name would start a second database.`,
|
|
450
|
+
calls: [(0, failure_1.suggest)(againTool(r), { database_name: recorded.databaseName }, 'Finish the provision recorded for this project')],
|
|
451
|
+
}, { ticketId: recorded.ticketId });
|
|
314
452
|
}
|
|
315
453
|
else {
|
|
316
454
|
current = recorded;
|
|
@@ -331,7 +469,6 @@ async function requestAndBind(r, input, env, replaced, exec) {
|
|
|
331
469
|
recovered = true;
|
|
332
470
|
}
|
|
333
471
|
}
|
|
334
|
-
const prewarm = startPrewarm(r, exec);
|
|
335
472
|
// Resolve the module set: pinned base preset from node-type-registry, then
|
|
336
473
|
// ordered overlays (host default < project-local provision.json). A bad
|
|
337
474
|
// preset/manifest fails the run rather than provisioning a wrong module set.
|
|
@@ -347,8 +484,14 @@ async function requestAndBind(r, input, env, replaced, exec) {
|
|
|
347
484
|
modules = (0, resolve_1.resolveProvisionModules)(layers);
|
|
348
485
|
}
|
|
349
486
|
catch (err) {
|
|
350
|
-
return
|
|
487
|
+
return refuse('failed', { message: `Cannot resolve provision modules: ${(0, graphql_http_1.thrownText)(err)}` });
|
|
351
488
|
}
|
|
489
|
+
const prewarm = startPrewarm(r, exec);
|
|
490
|
+
return afterPrewarm(await sendRequest(r, { current, recovered, abandoned, modules, replaced }, prewarm), prewarm);
|
|
491
|
+
}
|
|
492
|
+
async function sendRequest(r, request, prewarm) {
|
|
493
|
+
let { current, recovered } = request;
|
|
494
|
+
const { abandoned, modules, replaced } = request;
|
|
352
495
|
// requestDatabase claims a warm-pool database when the module set matches a
|
|
353
496
|
// cataloged preset and cold-provisions otherwise; the ticket is polled on the
|
|
354
497
|
// modules endpoint until the database AND its owner bootstrap complete. An
|
|
@@ -382,6 +525,8 @@ async function requestAndBind(r, input, env, replaced, exec) {
|
|
|
382
525
|
if (err instanceof request_database_1.ProvisionPendingError) {
|
|
383
526
|
return pendingResult(r, ticketFor(err.ticketId), err.message, recovered);
|
|
384
527
|
}
|
|
528
|
+
if (err instanceof request_database_1.ProvisionSignedOutError)
|
|
529
|
+
return signedOutWaiting(r, ticketFor(err.ticketId), err.message);
|
|
385
530
|
if (err instanceof request_database_1.ProvisionTicketLostError) {
|
|
386
531
|
// The ticket can't be read back, which doesn't mean the provision
|
|
387
532
|
// stopped. Follow another in-flight one of this name, or stop without
|
|
@@ -399,7 +544,11 @@ async function requestAndBind(r, input, env, replaced, exec) {
|
|
|
399
544
|
const checked = lookup.problem
|
|
400
545
|
? `the backend couldn't be asked for another one (${lookup.problem})`
|
|
401
546
|
: 'no other provision of that name is in progress';
|
|
402
|
-
return
|
|
547
|
+
return refuse('ticket-lost', {
|
|
548
|
+
message: `The provision of "${r.name}" (ticket ${err.ticketId}) can no longer be found on this backend, and ${checked}.`,
|
|
549
|
+
hint: 'Nothing was created, and the record is cleared, so calling again requests a new database.',
|
|
550
|
+
calls: [again(r, 'Request the database again')],
|
|
551
|
+
}, { ticketId: err.ticketId });
|
|
403
552
|
}
|
|
404
553
|
// A definitive failure ends the recorded request, so forget it.
|
|
405
554
|
if (current)
|
|
@@ -429,25 +578,109 @@ async function pendingResult(r, ticket, reason, recovered) {
|
|
|
429
578
|
recordedOk = false;
|
|
430
579
|
}
|
|
431
580
|
if (ticket.attempts > pending_ticket_1.MAX_PENDING_ATTEMPTS) {
|
|
432
|
-
return
|
|
581
|
+
return refuse('provision-stuck', {
|
|
582
|
+
message: `Database "${r.name}" is still not ready after ${pending_ticket_1.MAX_PENDING_ATTEMPTS} waits (${reason}). Its request (ticket ${ticketId}) stays recorded, and no other database is requested while it is in progress.`,
|
|
583
|
+
hint: "Check the backend's provisioning jobs.",
|
|
584
|
+
}, { ticketId });
|
|
433
585
|
}
|
|
434
|
-
const
|
|
586
|
+
const waiting = `call again with the same name, "${r.name}", to keep waiting on it`;
|
|
435
587
|
const message = recordedOk
|
|
436
|
-
? `Database "${r.name}" is still provisioning (${reason}). The request is recorded in .env; ${
|
|
437
|
-
: `Database "${r.name}" is still provisioning (${reason}). Recording its ticket in .env failed, but the backend still has it: ${
|
|
438
|
-
return {
|
|
588
|
+
? `Database "${r.name}" is still provisioning (${reason}). The request is recorded in .env; ${waiting}. Don't change the name: that starts a second database.`
|
|
589
|
+
: `Database "${r.name}" is still provisioning (${reason}). Recording its ticket in .env failed, but the backend still has it: ${waiting}. Don't change the name: that starts a second database.`;
|
|
590
|
+
return {
|
|
591
|
+
success: false,
|
|
592
|
+
message,
|
|
593
|
+
pending: true,
|
|
594
|
+
ticketId,
|
|
595
|
+
...(recovered ? { recovered: true } : {}),
|
|
596
|
+
// No details code: a pending call has not failed, it has not finished.
|
|
597
|
+
failure: {
|
|
598
|
+
code: 'provision-pending',
|
|
599
|
+
message,
|
|
600
|
+
retryable: true,
|
|
601
|
+
calls: [again(r, 'Keep waiting on the recorded request')],
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
// A failed ticket stores the job's error text, not a GraphQL error, so the
|
|
606
|
+
// code a refusal raised and PostgreSQL's own unique-violation text are the
|
|
607
|
+
// only signals it has; the request's own GraphQL answer has a code.
|
|
608
|
+
const TICKET_CODE_RE = /^(?:\[[^\]]*\]\s*)?([A-Z][A-Z0-9_]+)\b/;
|
|
609
|
+
const TICKET_UNIQUE_RE = /duplicate key value violates unique constraint/;
|
|
610
|
+
/** The public code of a refusal: from the request's GraphQL answer, or from a failed ticket. */
|
|
611
|
+
function refusalCode(err) {
|
|
612
|
+
if (err instanceof request_database_1.ProvisionJobError)
|
|
613
|
+
return TICKET_CODE_RE.exec(err.ticketError)?.[1];
|
|
614
|
+
const errors = err?.errors;
|
|
615
|
+
if (!Array.isArray(errors))
|
|
616
|
+
return undefined;
|
|
617
|
+
const code = errors.find((error) => error?.extensions?.class !== 'internal')?.extensions?.code;
|
|
618
|
+
return typeof code === 'string' ? code : undefined;
|
|
619
|
+
}
|
|
620
|
+
const isNameTaken = (err) => refusalCode(err) === 'UNIQUE_VIOLATION' || (err instanceof request_database_1.ProvisionJobError && TICKET_UNIQUE_RE.test(err.ticketError));
|
|
621
|
+
const REFUSED = 'Database provisioning was refused';
|
|
622
|
+
// The tool of the same call again: a replace from the tool is its own tool.
|
|
623
|
+
const againTool = (r) => (r.mode === 'replace' && r.viaTool ? 'replace_database' : 'provision_database');
|
|
624
|
+
// The same call again, with the same name.
|
|
625
|
+
const again = (r, why) => (0, failure_1.suggest)(againTool(r), { database_name: r.name }, why);
|
|
626
|
+
const anotherName = (r) => (0, failure_1.suggest)(againTool(r), {}, 'Request the database under a name that is free', ['database_name']);
|
|
627
|
+
// The backend refused a read of the provision because the sign-in ended. The provision may still be running, so its
|
|
628
|
+
// ticket stays recorded, and the next call after a sign-in waits on it instead of requesting another database.
|
|
629
|
+
async function signedOutWaiting(r, ticket, reason) {
|
|
630
|
+
const recorded = await updateEnvFile(r.envPath, (content) => (0, pending_ticket_1.recordPendingTicket)(content, ticket)).then(() => true, () => false);
|
|
631
|
+
return refuse('signed-out', {
|
|
632
|
+
message: `The backend did not accept the account credential while it read the provision of "${r.name}" (ticket ${ticket.ticketId}): ${reason}. ` +
|
|
633
|
+
`The database may still be on its way${recorded ? ', and the request stays recorded in .env' : ''}.`,
|
|
634
|
+
hint: `${r.host.signInHint ?? 'Sign in again'}, then call again with the same name to keep waiting on it. Don't change the name: that starts a second database.`,
|
|
635
|
+
calls: [again(r, 'Keep waiting on the recorded request once signed in')],
|
|
636
|
+
}, { ticketId: ticket.ticketId });
|
|
439
637
|
}
|
|
440
|
-
const NAME_TAKEN_RE = /already exists|already taken|already in use|duplicate/i;
|
|
441
638
|
async function requestFailure(r, err) {
|
|
442
|
-
const detail =
|
|
443
|
-
if (
|
|
444
|
-
return
|
|
639
|
+
const detail = (0, graphql_http_1.thrownText)(err);
|
|
640
|
+
if ((0, graphql_http_1.answersSignedOut)(err)) {
|
|
641
|
+
return refuse('signed-out', {
|
|
642
|
+
message: `${REFUSED}${refusalCode(err) ? ` (${refusalCode(err)})` : ''}: the backend did not accept the account credential.`,
|
|
643
|
+
hint: r.host.signInHint ?? 'Sign in again, then call again.',
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
switch (refusalCode(err)) {
|
|
647
|
+
case 'BILLING_PLAN_REQUIRED':
|
|
648
|
+
return refuse('plan-required', {
|
|
649
|
+
message: `${REFUSED} (BILLING_PLAN_REQUIRED): this account has no active plan, and this backend requires one before it creates a database.`,
|
|
650
|
+
hint: 'Choose a plan for this account under Billing → Plans in the Constructive dashboard, then call again.',
|
|
651
|
+
calls: [again(r, 'Request the database again once the account has a plan')],
|
|
652
|
+
});
|
|
653
|
+
case 'LIMIT_REACHED':
|
|
654
|
+
return refuse('limit-reached', {
|
|
655
|
+
message: `${REFUSED} (LIMIT_REACHED): this account has as many databases as its plan allows.`,
|
|
656
|
+
hint: 'Delete a database this account no longer needs, or choose a plan that allows more under Billing → Plans in the Constructive dashboard, then call again.',
|
|
657
|
+
calls: [again(r, 'Request the database again once the account has room for it')],
|
|
658
|
+
});
|
|
659
|
+
case 'BILLING_QUOTA_EXCEEDED':
|
|
660
|
+
return refuse('limit-reached', {
|
|
661
|
+
message: `${REFUSED} (BILLING_QUOTA_EXCEEDED): this account has used up the allowance of its plan.`,
|
|
662
|
+
hint: 'Choose a plan with a larger allowance under Billing → Plans in the Constructive dashboard, or wait for the allowance to renew, then call again.',
|
|
663
|
+
calls: [again(r, 'Request the database again once the allowance allows it')],
|
|
664
|
+
});
|
|
665
|
+
default:
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
if (!isNameTaken(err))
|
|
669
|
+
return refuse('failed', { message: `Database provisioning failed: ${detail}.` });
|
|
445
670
|
const heldBy = await ownHolder(r);
|
|
446
671
|
if (heldBy) {
|
|
447
672
|
const when = heldBy.createdAt ? `, requested ${heldBy.createdAt}` : '';
|
|
448
|
-
return
|
|
449
|
-
|
|
450
|
-
|
|
673
|
+
return refuse('name-taken', {
|
|
674
|
+
message: `Database provisioning failed: ${detail}. The name "${r.name}" belongs to a database this account provisioned earlier (ID ${heldBy.databaseId}${when}) that this project isn't bound to, so it was not bound.`,
|
|
675
|
+
hint: 'Call again with another database name.',
|
|
676
|
+
calls: [anotherName(r)],
|
|
677
|
+
}, { heldBy });
|
|
678
|
+
}
|
|
679
|
+
return refuse('name-taken', {
|
|
680
|
+
message: `Database provisioning failed: ${detail}. The database name is already taken on the backend.`,
|
|
681
|
+
hint: 'Call again with another database name.',
|
|
682
|
+
calls: [anotherName(r)],
|
|
683
|
+
});
|
|
451
684
|
}
|
|
452
685
|
// A completed provision of this name by this account whose database still
|
|
453
686
|
// exists under it: reported with name-taken so the host can adopt it.
|
|
@@ -481,7 +714,15 @@ async function saveBinding(r, binding, ticket) {
|
|
|
481
714
|
// Keep the ticket recorded, so the next call resumes it and binds it.
|
|
482
715
|
if (ticket)
|
|
483
716
|
await updateEnvFile(r.envPath, (content) => (0, pending_ticket_1.recordPendingTicket)(content, ticket)).catch(noop);
|
|
484
|
-
return
|
|
717
|
+
return refuse('binding-not-saved', {
|
|
718
|
+
message: `Database "${binding.databaseName}" (ID ${binding.databaseId}) is ready, but the app couldn't save the binding (${(0, graphql_http_1.thrownText)(err)}), so .env was left unchanged.`,
|
|
719
|
+
...(ticket
|
|
720
|
+
? {
|
|
721
|
+
hint: 'Calling again with the same name binds it.',
|
|
722
|
+
calls: [again(r, 'Bind the database that is ready')],
|
|
723
|
+
}
|
|
724
|
+
: {}),
|
|
725
|
+
}, { databaseId: binding.databaseId, ...(ticket ? { ticketId: ticket.ticketId } : {}) });
|
|
485
726
|
}
|
|
486
727
|
}
|
|
487
728
|
async function bindDatabase(r, bind, prewarm) {
|
|
@@ -493,7 +734,7 @@ async function bindDatabase(r, bind, prewarm) {
|
|
|
493
734
|
if (ticket) {
|
|
494
735
|
return pendingResult(r, ticket, `provisioned, but its owner couldn't be confirmed: ${owner.detail}`, bind.recovered);
|
|
495
736
|
}
|
|
496
|
-
return
|
|
737
|
+
return unanswered(owner, `Cannot verify database ${databaseId}: ${owner.detail}.`, 'Retry once the backend answers.');
|
|
497
738
|
}
|
|
498
739
|
const visible = owner.status !== 'missing';
|
|
499
740
|
if (!visible || owner.ownerId !== r.ownerId) {
|
|
@@ -501,12 +742,18 @@ async function bindDatabase(r, bind, prewarm) {
|
|
|
501
742
|
await updateEnvFile(r.envPath, pending_ticket_1.clearPendingTicket).catch(noop);
|
|
502
743
|
const why = visible ? "it isn't owned by" : "it isn't visible to";
|
|
503
744
|
if (bind.adopted) {
|
|
504
|
-
return
|
|
745
|
+
return refuse(visible ? 'account-mismatch' : 'db-missing', {
|
|
746
|
+
message: `Database ${databaseId} was not bound: ${why} the signed-in account.`,
|
|
747
|
+
});
|
|
505
748
|
}
|
|
506
|
-
return
|
|
749
|
+
return refuse('failed', {
|
|
750
|
+
message: `Database provisioning returned database ${databaseId}, but ${why} the signed-in account, so it was not bound.`,
|
|
751
|
+
hint: 'Call again to request a new database.',
|
|
752
|
+
calls: [again(r, 'Request a new database')],
|
|
753
|
+
});
|
|
507
754
|
}
|
|
508
755
|
if (bind.adopted && owner.status === 'suspended') {
|
|
509
|
-
return
|
|
756
|
+
return refuse('db-suspended', { message: suspendedText(databaseId, owner) });
|
|
510
757
|
}
|
|
511
758
|
const saved = await saveBinding(r, {
|
|
512
759
|
cwd: r.cwd,
|
|
@@ -531,22 +778,21 @@ async function bindDatabase(r, bind, prewarm) {
|
|
|
531
778
|
})));
|
|
532
779
|
}
|
|
533
780
|
catch (err) {
|
|
534
|
-
return
|
|
781
|
+
return refuse('env-write-failed', { message: `Database provisioned (ID: ${databaseId}) but writing .env failed: ${(0, graphql_http_1.thrownText)(err)}` }, { databaseId });
|
|
535
782
|
}
|
|
536
783
|
// Settle the concurrent prewarm so the scaffold + install are in place before
|
|
537
784
|
// run_codegen runs. A failure here is non-fatal: run_codegen redoes the work.
|
|
538
|
-
const prewarmed = (await prewarm).ok ? ' packages/app
|
|
785
|
+
const prewarmed = (await prewarm).ok ? ' packages/app is ready.' : '';
|
|
539
786
|
const notes = [
|
|
540
|
-
bind.resumed ? ' Finished
|
|
541
|
-
bind.recovered ? ' Found it on the backend by name
|
|
787
|
+
bind.resumed ? ' Finished an earlier request.' : '',
|
|
788
|
+
bind.recovered ? ' Found it on the backend by name.' : '',
|
|
542
789
|
prewarmed,
|
|
543
|
-
bind.replaced
|
|
544
|
-
? ' Previous binding archived in .env (old database kept); rebuild the schema with provision_blueprint + run_codegen.'
|
|
545
|
-
: '',
|
|
790
|
+
bind.replaced ? ' The old binding is archived in .env, and the old database keeps its data. Build the schema again here.' : '',
|
|
546
791
|
].join('');
|
|
792
|
+
const named = `${r.name} (${databaseId.slice(0, 8)})`;
|
|
547
793
|
const message = bind.adopted
|
|
548
|
-
? `Bound
|
|
549
|
-
: `
|
|
794
|
+
? `Bound this directory to ${named}. Wrote .env.${notes}`
|
|
795
|
+
: `Created ${named} and bound this directory to it. Wrote .env.${notes}`;
|
|
550
796
|
return {
|
|
551
797
|
success: true,
|
|
552
798
|
message,
|