Skip to content

Commit d560e75

Browse files
sshaderConvex, Inc.
authored and
Convex, Inc.
committed
[cli] Fix bugs around --configure and saving the wrong deployment name (#35753)
The previous code was only respecting `--configure=new`, not `--configure=existing` or `--configure` (I'll look into adding a test). There was also a bug where `npx convex dev` with a prod deployment stored in `CONVEX_DEPLOYMENT` would update the `CONVEX_DEPLOYMENT` to `dev:<name of prod deployment>` (but would still push to the right deployment) GitOrigin-RevId: a2367f2b4fdca4517a0e466d61e11c90f27c2891
1 parent d560673 commit d560e75

File tree

2 files changed

+71
-53
lines changed

2 files changed

+71
-53
lines changed

npm-packages/convex/src/cli/configure.ts

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,56 @@ export async function deploymentCredentialsOrConfigure(
112112
teamSlug: string | null;
113113
} | null;
114114
}
115+
> {
116+
const selectedDeployment = await _deploymentCredentialsOrConfigure(
117+
ctx,
118+
deploymentSelection,
119+
chosenConfiguration,
120+
cmdOptions,
121+
partitionId,
122+
);
123+
124+
if (selectedDeployment.deploymentFields !== null) {
125+
await updateEnvAndConfigForDeploymentSelection(
126+
ctx,
127+
{
128+
url: selectedDeployment.url,
129+
deploymentName: selectedDeployment.deploymentFields.deploymentName,
130+
teamSlug: selectedDeployment.deploymentFields.teamSlug,
131+
projectSlug: selectedDeployment.deploymentFields.projectSlug,
132+
deploymentType: selectedDeployment.deploymentFields
133+
.deploymentType as DeploymentType,
134+
},
135+
deploymentNameFromSelection(deploymentSelection),
136+
);
137+
} else {
138+
await handleManuallySetUrlAndAdminKey(ctx, {
139+
url: selectedDeployment.url,
140+
adminKey: selectedDeployment.adminKey,
141+
});
142+
}
143+
return {
144+
url: selectedDeployment.url,
145+
adminKey: selectedDeployment.adminKey,
146+
deploymentFields: selectedDeployment.deploymentFields,
147+
};
148+
}
149+
150+
export async function _deploymentCredentialsOrConfigure(
151+
ctx: Context,
152+
deploymentSelection: DeploymentSelection,
153+
chosenConfiguration: ChosenConfiguration,
154+
cmdOptions: ConfigureCmdOptions,
155+
partitionId?: number | undefined,
156+
): Promise<
157+
DeploymentCredentials & {
158+
deploymentFields: {
159+
deploymentName: DeploymentName;
160+
deploymentType: string;
161+
projectSlug: string | null;
162+
teamSlug: string | null;
163+
} | null;
164+
}
115165
> {
116166
const config = readGlobalConfig(ctx);
117167
const globallyForceCloud = !!config?.optOutOfLocalDevDeploymentsUntilBetaOver;
@@ -174,12 +224,7 @@ export async function deploymentCredentialsOrConfigure(
174224
overrideAuthUsername: cmdOptions.overrideAuthUsername,
175225
overrideAuthPassword: cmdOptions.overrideAuthPassword,
176226
});
177-
const accessResult = await checkAccessToSelectedProject(
178-
ctx,
179-
deploymentSelection.targetProject,
180-
);
181-
if (accessResult.kind === "noAccess") {
182-
logMessage(ctx, "You don't have access to the selected project.");
227+
if (chosenConfiguration !== null) {
183228
const result = await handleChooseProject(
184229
ctx,
185230
chosenConfiguration,
@@ -191,7 +236,13 @@ export async function deploymentCredentialsOrConfigure(
191236
);
192237
return result;
193238
}
194-
if (chosenConfiguration === "new") {
239+
240+
const accessResult = await checkAccessToSelectedProject(
241+
ctx,
242+
deploymentSelection.targetProject,
243+
);
244+
if (accessResult.kind === "noAccess") {
245+
logMessage(ctx, "You don't have access to the selected project.");
195246
const result = await handleChooseProject(
196247
ctx,
197248
chosenConfiguration,
@@ -211,33 +262,17 @@ export async function deploymentCredentialsOrConfigure(
211262
// We'll start running it below
212263
{ ensureLocalRunning: false },
213264
);
214-
215-
if (selectedDeployment.deploymentFields !== null) {
216-
await updateEnvAndConfigForDeploymentSelection(
217-
ctx,
218-
{
219-
url: selectedDeployment.url,
220-
deploymentName: selectedDeployment.deploymentFields.deploymentName,
221-
teamSlug: selectedDeployment.deploymentFields.teamSlug,
222-
projectSlug: selectedDeployment.deploymentFields.projectSlug,
223-
deploymentType: selectedDeployment.deploymentFields
224-
.deploymentType as DeploymentType,
225-
},
226-
deploymentNameFromSelection(deploymentSelection),
227-
);
228-
if (
229-
selectedDeployment.deploymentFields !== null &&
230-
selectedDeployment.deploymentFields.deploymentType === "local"
231-
) {
232-
await handleLocalDeployment(ctx, {
233-
teamSlug: selectedDeployment.deploymentFields.teamSlug!,
234-
projectSlug: selectedDeployment.deploymentFields.projectSlug!,
235-
forceUpgrade: cmdOptions.localOptions.forceUpgrade,
236-
ports: cmdOptions.localOptions.ports,
237-
backendVersion: cmdOptions.localOptions.backendVersion,
238-
});
239-
}
240-
return selectedDeployment;
265+
if (
266+
selectedDeployment.deploymentFields !== null &&
267+
selectedDeployment.deploymentFields.deploymentType === "local"
268+
) {
269+
await handleLocalDeployment(ctx, {
270+
teamSlug: selectedDeployment.deploymentFields.teamSlug!,
271+
projectSlug: selectedDeployment.deploymentFields.projectSlug!,
272+
forceUpgrade: cmdOptions.localOptions.forceUpgrade,
273+
ports: cmdOptions.localOptions.ports,
274+
backendVersion: cmdOptions.localOptions.backendVersion,
275+
});
241276
}
242277
return {
243278
url: selectedDeployment.url,
@@ -299,17 +334,6 @@ async function handleChooseProject(
299334
deploymentOptions,
300335
partitionId: args.partitionId,
301336
});
302-
await updateEnvAndConfigForDeploymentSelection(
303-
ctx,
304-
{
305-
url,
306-
deploymentName,
307-
teamSlug: project.teamSlug,
308-
projectSlug: project.projectSlug,
309-
deploymentType: deploymentOptions.kind,
310-
},
311-
null,
312-
);
313337
return {
314338
url,
315339
adminKey,

npm-packages/convex/src/cli/lib/api.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ async function fetchExistingDevDeploymentCredentialsOrCrash(
378378
undefined,
379379
);
380380
return {
381-
deploymentName,
381+
deploymentName: credentials.deploymentName,
382382
adminKey: credentials.adminKey,
383383
url: credentials.deploymentUrl,
384384
deploymentType: "dev",
@@ -413,16 +413,10 @@ async function handleOwnDev(
413413
deploymentType: "local",
414414
};
415415
}
416-
// Note -- this returns the deployment with that name iff it's a dev deployment,
417-
// but it does not actually check that the deployment belongs to the current member.
418-
const credentials = await fetchExistingDevDeploymentCredentialsOrCrash(
416+
return await fetchExistingDevDeploymentCredentialsOrCrash(
419417
ctx,
420418
projectSelection.deploymentName,
421419
);
422-
return {
423-
...credentials,
424-
deploymentName: projectSelection.deploymentName,
425-
};
426420
}
427421
case "teamAndProjectSlugs":
428422
case "projectDeployKey": {

0 commit comments

Comments
 (0)