Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/cli/lib/components.codegen.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from "vitest";
import { isDryRunStartPush } from "./components.js";

describe("isDryRunStartPush", () => {
it("marks codegen pushes as dry runs so start_push does not create tables or indexes", () => {
// A normal deploy mutates the deployment.
expect(isDryRunStartPush({ dryRun: false, codegen: false })).toBe(false);
// `npx convex deploy --dry-run` previews without mutating.
expect(isDryRunStartPush({ dryRun: true, codegen: false })).toBe(true);
// `npx convex codegen` is read-only: it needs the backend's evaluated
// schema for the generated bindings, but it must not create tables or
// indexes on the deployment (convex/convex-js#199).
expect(isDryRunStartPush({ dryRun: false, codegen: true })).toBe(true);
expect(isDryRunStartPush({ dryRun: true, codegen: true })).toBe(true);
});
});
30 changes: 28 additions & 2 deletions src/cli/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ async function getUnchangedModuleHashesFromServer(
);
}

/**
* Whether the start_push request should be marked as a dry run.
*
* Codegen needs the backend's evaluated schema to generate the TypeScript
* bindings, but it must not modify the deployment (`npx convex codegen
* --help` says it doesn't). Marking the push as a dry run keeps
* `start_push` from creating tables or indexes on the deployment.
* See https://github.com/convex/convex-js/issues/199.
*/
export function isDryRunStartPush(options: {
dryRun: boolean;
codegen: boolean;
}): boolean {
return options.dryRun || options.codegen;
}

async function startComponentsPushAndCodegen(
ctx: Context,
parentSpan: Span,
Expand Down Expand Up @@ -459,7 +475,11 @@ async function startComponentsPushAndCodegen(
}
const startPushRequest = {
adminKey: options.adminKey,
dryRun: options.dryRun,
// Codegen is a read-only operation: it needs the backend's evaluated
// schema for the generated bindings, but it must not create tables or
// indexes on the deployment. `dryRun` is the protocol's established
// "don't mutate" signal (`npx convex deploy --dry-run` relies on it).
dryRun: isDryRunStartPush(options),
functions: projectConfig.functions,
appDefinition,
componentDefinitions,
Expand Down Expand Up @@ -547,7 +567,13 @@ async function startComponentsPushAndCodegen(
);
}

changeSpinner("Uploading functions to Convex...");
changeSpinner(
// Codegen never uploads anything (see isDryRunStartPush above), so the
// deploy-oriented spinner text would be misleading here.
options.codegen
? "Analyzing functions for codegen..."
: "Uploading functions to Convex...",
);
const startPushResponse = await parentSpan.enterAsync("startPush", (span) =>
startPush(ctx, span, startPushRequest, options),
);
Expand Down