Skip to content

Commit

Permalink
npx convex import --replace-all (#31724)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ldanilek authored and Convex, Inc. committed Nov 22, 2024
1 parent b213890 commit 7543354
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/cli/convexImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7543354

Please sign in to comment.