Skip to content

Commit bad3a91

Browse files
NicolappsConvex, Inc.
authored andcommitted
cli: Restore the large index deletion check (#43101)
GitOrigin-RevId: aab2b4c20911efa178c9e6322ba93a41008d9cd8
1 parent ca5318c commit bad3a91

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { evaluatePush } from "./deploy2.js";
1414
import { DeveloperIndexConfig, IndexDiff } from "./deployApi/finishPush.js";
1515
import { runSystemQuery } from "./run.js";
1616

17-
const MIN_DOCUMENTS_FOR_INDEX_DELETE_WARNING = 10_000_000;
17+
const MIN_DOCUMENTS_FOR_INDEX_DELETE_WARNING = 100_000;
1818

1919
export async function checkForLargeIndexDeletion({
2020
ctx,
@@ -90,9 +90,10 @@ export async function checkForLargeIndexDeletion({
9090
}),
9191
);
9292

93+
const minDocumentsForWarning = minDocumentsForIndexDeleteWarning();
9394
if (
9495
!deletedIndexesWithDocumentsCount.some(
95-
({ count }) => count >= MIN_DOCUMENTS_FOR_INDEX_DELETE_WARNING,
96+
({ count }) => count >= minDocumentsForWarning,
9697
)
9798
) {
9899
logFinishedStep("No large indexes are deleted by this push");
@@ -104,12 +105,13 @@ from your production deployment (${options.url}):
104105
105106
${deletedIndexesWithDocumentsCount
106107
.map(({ componentDefinitionPath, index, count }) =>
107-
formatDeletedIndex(
108+
formatDeletedIndex({
108109
componentDefinitionPath,
109110
index,
110-
indexDiffs[componentDefinitionPath],
111-
count,
112-
),
111+
indexDiff: indexDiffs[componentDefinitionPath],
112+
documentsCount: count,
113+
minDocumentsForWarning,
114+
}),
113115
)
114116
.join("\n")}
115117
@@ -151,19 +153,26 @@ to be backfilled again if you want to restore it later.
151153
logFinishedStep("Proceeding with push.");
152154
}
153155

154-
function formatDeletedIndex(
155-
componentDefinitionPath: string,
156-
index: DeveloperIndexConfig,
157-
indexDiff: IndexDiff,
158-
documentsCount: number,
159-
) {
156+
function formatDeletedIndex({
157+
componentDefinitionPath,
158+
index,
159+
indexDiff,
160+
documentsCount,
161+
minDocumentsForWarning,
162+
}: {
163+
componentDefinitionPath: string;
164+
index: DeveloperIndexConfig;
165+
indexDiff: IndexDiff;
166+
documentsCount: number;
167+
minDocumentsForWarning: number;
168+
}) {
160169
const componentNameFormatted =
161170
componentDefinitionPath !== ""
162171
? `${chalk.gray(componentDefinitionPath)}:`
163172
: "";
164173

165174
const documentsCountFormatted =
166-
documentsCount >= MIN_DOCUMENTS_FOR_INDEX_DELETE_WARNING
175+
documentsCount >= minDocumentsForWarning
167176
? ` ${chalk.yellowBright(`⚠️ ${documentsCount.toLocaleString()} documents`)}`
168177
: ` ${documentsCount.toLocaleString()} ${documentsCount === 1 ? "document" : "documents"}`;
169178

@@ -185,3 +194,14 @@ function getTableName(index: DeveloperIndexConfig) {
185194
const [tableName, _indexName] = index.name.split(".");
186195
return tableName;
187196
}
197+
198+
function minDocumentsForIndexDeleteWarning(): number {
199+
const envValue = process.env.CONVEX_MIN_DOCUMENTS_FOR_INDEX_DELETE_WARNING;
200+
if (envValue !== undefined) {
201+
const parsed = parseInt(envValue, 10);
202+
if (!isNaN(parsed)) {
203+
return parsed;
204+
}
205+
}
206+
return MIN_DOCUMENTS_FOR_INDEX_DELETE_WARNING;
207+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { DEFINITION_FILENAME_TS } from "./components/constants.js";
5454
import { DeploymentSelection } from "./deploymentSelection.js";
5555
import { deploymentDashboardUrlPage } from "./dashboard.js";
5656
import { formatIndex, LargeIndexDeletionCheck } from "./indexes.js";
57+
import { checkForLargeIndexDeletion } from "./checkForLargeIndexDeletion.js";
5758
import { LogManager } from "./logs.js";
5859

5960
export type PushOptions = {
@@ -365,6 +366,19 @@ async function startComponentsPushAndCodegen(
365366
}
366367
logStartPushSizes(parentSpan, startPushRequest);
367368

369+
if (options.largeIndexDeletionCheck !== "no verification") {
370+
await parentSpan.enterAsync("checkForLargeIndexDeletion", (span) =>
371+
checkForLargeIndexDeletion({
372+
ctx,
373+
span,
374+
request: startPushRequest,
375+
options,
376+
askForConfirmation:
377+
options.largeIndexDeletionCheck === "ask for confirmation",
378+
}),
379+
);
380+
}
381+
368382
changeSpinner("Uploading functions to Convex...");
369383
const startPushResponse = await parentSpan.enterAsync("startPush", (span) =>
370384
startPush(ctx, span, startPushRequest, options),

0 commit comments

Comments
 (0)