From 7543354bdae1e5889b54e20afdbba0189b0b7811 Mon Sep 17 00:00:00 2001 From: Lee Danilek Date: Fri, 22 Nov 2024 13:16:14 -0500 Subject: [PATCH] npx convex import --replace-all (#31724) add `--replace-all` flag to the CLI command `npx convex import`. This behaves the same as the Restore functionality in the dashboard. The behavior is useful from the CLI as well. It allows you to effectively clear all of a deployment's tables with a cleaner solution than we otherwise provide. Tested against a local backend and it worked as expected, clearing a table that was in the schema and deleting a table that wasn't. Smoke test works too. GitOrigin-RevId: cf925c3fc915c7c32761403f254d92ba8ea40869 --- src/cli/convexImport.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cli/convexImport.ts b/src/cli/convexImport.ts index aff39cf..7c7cba3 100644 --- a/src/cli/convexImport.ts +++ b/src/cli/convexImport.ts @@ -54,13 +54,24 @@ export const convexImport = new Command("import") new Option( "--replace", "Replace all existing data in any of the imported tables", - ).conflicts("--append"), + ) + .conflicts("--append") + .conflicts("--replace-all"), + ) + .addOption( + new Option("--append", "Append imported data to any existing tables") + .conflicts("--replace-all") + .conflicts("--replace"), ) .addOption( new Option( - "--append", - "Append imported data to any existing tables", - ).conflicts("--replace"), + "--replace-all", + "Replace all existing data in the deployment with the imported tables,\n" + + " deleting tables that don't appear in the import file or the schema,\n" + + " and clearing tables that appear in the schema but not in the import file", + ) + .conflicts("--append") + .conflicts("--replace"), ) .option( "-y, --yes", @@ -160,6 +171,8 @@ export const convexImport = new Command("import") mode = "append"; } else if (options.replace) { mode = "replace"; + } else if (options.replaceAll) { + mode = "replaceAll"; } const importArgs = { tableName: tableName === null ? undefined : tableName,