ardent-cli 0.0.2 → 0.0.3
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.
- package/dist/index.js +17 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -438,6 +438,17 @@ function truncate(str, maxLen) {
|
|
|
438
438
|
if (str.length <= maxLen) return str;
|
|
439
439
|
return str.slice(0, maxLen - 2) + "..";
|
|
440
440
|
}
|
|
441
|
+
function parseDiffRow(raw) {
|
|
442
|
+
return {
|
|
443
|
+
schema_name: raw.schema_name,
|
|
444
|
+
table_name: raw.table_name,
|
|
445
|
+
primary_key: raw.primary_key,
|
|
446
|
+
first_op: raw.first_op,
|
|
447
|
+
last_op: raw.last_op,
|
|
448
|
+
first_data: raw.original_values ? JSON.parse(raw.original_values) : null,
|
|
449
|
+
last_data: raw.final_values ? JSON.parse(raw.final_values) : null
|
|
450
|
+
};
|
|
451
|
+
}
|
|
441
452
|
var diffCommand = new Command3("diff").description("Show CDC changes on current branch").option("-b, --branch <name>", "Branch name (defaults to current)").option("--sql", "Output as replay SQL").action(async (options) => {
|
|
442
453
|
let branch;
|
|
443
454
|
if (options.branch) {
|
|
@@ -460,13 +471,15 @@ var diffCommand = new Command3("diff").description("Show CDC changes on current
|
|
|
460
471
|
return;
|
|
461
472
|
}
|
|
462
473
|
try {
|
|
463
|
-
const
|
|
464
|
-
if (!
|
|
474
|
+
const stateRaw = await api.get(`/v1/branches/${branch.job_id}/state`);
|
|
475
|
+
if (!stateRaw || Object.keys(stateRaw).length === 0) {
|
|
465
476
|
console.log("No changes captured");
|
|
466
477
|
return;
|
|
467
478
|
}
|
|
468
|
-
for (const [_branchId,
|
|
469
|
-
const
|
|
479
|
+
for (const [_branchId, branchStateRaw] of Object.entries(stateRaw)) {
|
|
480
|
+
const ddl = branchStateRaw.ddl;
|
|
481
|
+
const replay_sql = branchStateRaw.replay_sql;
|
|
482
|
+
const diff = (branchStateRaw.diff || []).map(parseDiffRow);
|
|
470
483
|
if (options.sql) {
|
|
471
484
|
if (replay_sql) {
|
|
472
485
|
console.log(replay_sql);
|