@batadata/cli 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -859,8 +859,9 @@ export async function importDb(args) {
859
859
  }
860
860
  if (namedHits.length > 0 && !jsonMode) {
861
861
  warn(`Source contains ${namedHits.join(", ")}, which shares a name with BataDB's seeded ` +
862
- 'platform scaffolding on the target. The restore will likely fail with "relation already ' +
863
- 'exists" rename or exclude it on the source to migrate cleanly.');
862
+ "platform scaffolding. On a freshly created target the seeded copy is dropped so the " +
863
+ "source's version restores as real data; importing into an existing --project target " +
864
+ 'will likely fail with "relation already exists".');
864
865
  }
865
866
  // ── Phase 2: check pg_dump AND psql are new enough ──────────────────────────
866
867
  // BOTH matter: pg_dump can't dump a newer server than itself, and psql must be
@@ -1072,6 +1073,27 @@ export async function importDb(args) {
1072
1073
  const strandedHintJson = "The target project was left in place (NOT deleted) for diagnosis/retry — re-run with " +
1073
1074
  `--project ${targetProjectId} --yes after fixing` +
1074
1075
  (created ? `, or remove it with: bata projects delete ${targetProjectId} --yes.` : ".");
1076
+ // A freshly CREATED target's named scaffolding (public.health_check + its
1077
+ // sequence) is disposable furniture — but the SOURCE may carry same-named
1078
+ // tables (always true migrating FROM another BataDB, where provisioning
1079
+ // seeded them too). Doctrine says source objects are real data and must
1080
+ // restore + verify normally, so drop the target's seeded copies first;
1081
+ // otherwise the restore is GUARANTEED to die on "already exists". Never
1082
+ // touched on a --project target (created === false): its objects may be the
1083
+ // user's own data, and the old collide-loudly behavior stays.
1084
+ if (created && namedHits.length > 0) {
1085
+ phase("Dropping seeded scaffolding the source will re-create");
1086
+ for (const qn of namedHits) {
1087
+ const dot = qn.indexOf(".");
1088
+ const dropSql = `DROP TABLE IF EXISTS ${quoteIdent(qn.slice(0, dot))}.${quoteIdent(qn.slice(dot + 1))} CASCADE`;
1089
+ const dropRes = runPsql(targetUri, dropSql);
1090
+ if (dropRes.code !== 0) {
1091
+ emitError("RESTORE_FAILED", `Could not clear the target's seeded ${qn} before restore.`, `The source has its own ${qn}, which cannot restore over the target's seeded copy. ` +
1092
+ strandedHintJson, 1);
1093
+ return;
1094
+ }
1095
+ }
1096
+ }
1075
1097
  // ── Phase 4: migrate ───────────────────────────────────────────────────────
1076
1098
  phase("Migrating schema + data (pg_dump | psql)");
1077
1099
  const migration = await runMigration(source, targetUri);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batadata/cli",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "CLI for BataDB — serverless Postgres platform",
5
5
  "bin": {
6
6
  "bata": "./dist/index.js"