@lark-apaas/miaoda-cli 0.1.3-alpha.67da0bb → 0.1.3-alpha.70f9b2d
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/api/db/api.js +49 -15
- package/dist/api/db/client.js +61 -3
- package/dist/api/db/index.js +2 -1
- package/dist/api/file/client.js +40 -0
- package/dist/cli/commands/db/index.js +9 -0
- package/dist/cli/commands/file/index.js +1 -1
- package/dist/cli/handlers/db/_destructive.js +67 -0
- package/dist/cli/handlers/db/_env.js +26 -0
- package/dist/cli/handlers/db/_operator.js +35 -0
- package/dist/cli/handlers/db/audit.js +104 -15
- package/dist/cli/handlers/db/changelog.js +37 -7
- package/dist/cli/handlers/db/migration.js +25 -26
- package/dist/cli/handlers/db/recovery.js +124 -65
- package/dist/cli/handlers/file/rm.js +8 -6
- package/dist/utils/poll.js +21 -13
- package/dist/utils/spinner.js +46 -0
- package/package.json +1 -1
|
@@ -44,6 +44,8 @@ const error_1 = require("../../../utils/error");
|
|
|
44
44
|
const output_1 = require("../../../utils/output");
|
|
45
45
|
const render_1 = require("../../../utils/render");
|
|
46
46
|
const time_1 = require("../../../utils/time");
|
|
47
|
+
const _operator_1 = require("../../../cli/handlers/db/_operator");
|
|
48
|
+
const index_1 = require("../../../api/db/index");
|
|
47
49
|
const VALID_RETENTION = new Set(['7d', '30d', '180d', '360d', 'forever']);
|
|
48
50
|
async function handleDbAuditStatus(table, opts) {
|
|
49
51
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
@@ -198,25 +200,57 @@ async function handleDbAuditList(tables, opts) {
|
|
|
198
200
|
// 后端管理(本质也是 ISO 时间),CLI 不再混用 cursor/since。
|
|
199
201
|
const since = normalizeTime(opts.since, '--since');
|
|
200
202
|
const until = normalizeTime(opts.until, '--until');
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
203
|
+
// 多表场景:dataloom 对"任一表不存在"是 fail-fast(typo 应立即可见,符合 PRD 单表语义),
|
|
204
|
+
// 但 PRD 多表语义是"其他表继续返回,底部汇总跳过情况"。CLI 在这里前置校验:用 getSchema
|
|
205
|
+
// 的 tableNames 过滤模式(dataloom 端内存过滤,不存在的表静默忽略,不报错)拿到存在的
|
|
206
|
+
// 表集合,本地 diff 出缺失表,再用过滤后的表去查 listAuditLog。单表场景跳过预校验。
|
|
207
|
+
const isMulti = tables.length > 1;
|
|
208
|
+
let queryTables = tables;
|
|
209
|
+
const localMissing = [];
|
|
210
|
+
if (isMulti) {
|
|
211
|
+
const schemaResp = await api.db.getSchema({
|
|
212
|
+
appId,
|
|
213
|
+
tableNames: tables.join(','),
|
|
214
|
+
dbBranch: opts.env,
|
|
215
|
+
});
|
|
216
|
+
const existing = new Set((0, index_1.flattenSchemaList)(schemaResp.schema).map((t) => t.name));
|
|
217
|
+
for (const t of tables) {
|
|
218
|
+
if (!existing.has(t))
|
|
219
|
+
localMissing.push(t);
|
|
220
|
+
}
|
|
221
|
+
queryTables = tables.filter((t) => existing.has(t));
|
|
222
|
+
if (queryTables.length === 0) {
|
|
223
|
+
throw new error_1.AppError('TABLE_NOT_FOUND', `None of the requested tables exist: ${localMissing.join(', ')}`, { next_actions: ['Run `miaoda db schema list` to see all tables.'] });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let result;
|
|
227
|
+
try {
|
|
228
|
+
result = await api.db.listAuditLog({
|
|
229
|
+
appId,
|
|
230
|
+
tables: queryTables,
|
|
231
|
+
since,
|
|
232
|
+
until,
|
|
233
|
+
limit,
|
|
234
|
+
cursor: opts.cursor,
|
|
235
|
+
dbBranch: opts.env,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
throw decorateAuditListError(err, tables);
|
|
240
|
+
}
|
|
210
241
|
const visible = result.items;
|
|
211
|
-
|
|
242
|
+
// 服务端 skipped(audit 未启用,bare 名)+ CLI 本地探测 missing 合并;
|
|
243
|
+
// localMissing 自带 `(table not found)` 后缀,formatSkippedHint 透传渲染
|
|
244
|
+
const skipped = [...result.skipped, ...localMissing.map((t) => `${t} (table not found)`)];
|
|
212
245
|
// PRD JSON:data 是数组,元素是事件对象(snake_case),分页信封 next_cursor / has_more
|
|
246
|
+
// operator 后端用 JSON 字符串内嵌 {id, name},--json 输出还原成对象供下游消费
|
|
213
247
|
if ((0, output_1.isJsonMode)()) {
|
|
214
248
|
const items = visible.map((it) => ({
|
|
215
249
|
event_id: it.eventId,
|
|
216
250
|
event_time: it.eventTime,
|
|
217
251
|
target_table: it.targetTable,
|
|
218
252
|
type: it.type,
|
|
219
|
-
operator: it.operator,
|
|
253
|
+
operator: (0, _operator_1.parseOperator)(it.operator),
|
|
220
254
|
summary: it.summary,
|
|
221
255
|
// before/after 服务端是 JSON 字符串,反序列化回结构化对象供下游消费
|
|
222
256
|
...(it.before !== undefined ? { before: safeParseJson(it.before) } : {}),
|
|
@@ -224,7 +258,7 @@ async function handleDbAuditList(tables, opts) {
|
|
|
224
258
|
}));
|
|
225
259
|
(0, output_1.emitPaged)(items, result.nextCursor, result.hasMore);
|
|
226
260
|
if (skipped.length > 0) {
|
|
227
|
-
process.stderr.write(
|
|
261
|
+
process.stderr.write(formatSkippedHint(skipped, tables.length) + '\n');
|
|
228
262
|
}
|
|
229
263
|
if (visible.length === 0)
|
|
230
264
|
process.exitCode = 1;
|
|
@@ -233,7 +267,7 @@ async function handleDbAuditList(tables, opts) {
|
|
|
233
267
|
if (visible.length === 0) {
|
|
234
268
|
(0, output_1.emit)('No audit log entries found.');
|
|
235
269
|
if (skipped.length > 0) {
|
|
236
|
-
process.stderr.write(
|
|
270
|
+
process.stderr.write(formatSkippedHint(skipped, tables.length) + '\n');
|
|
237
271
|
}
|
|
238
272
|
process.exitCode = 1;
|
|
239
273
|
return;
|
|
@@ -247,12 +281,19 @@ async function handleDbAuditList(tables, opts) {
|
|
|
247
281
|
const rows = visible.map((it) => {
|
|
248
282
|
const eventTime = (0, render_1.formatTime)(it.eventTime, tty);
|
|
249
283
|
// event_id 完整透传——PRD 截图里的 "..." 只是文档省略写法,不是 CLI 行为
|
|
250
|
-
|
|
284
|
+
// operator pretty 只展示 name;--json 上面已经走 parseOperator 输出 {id, name}
|
|
285
|
+
const cells = [
|
|
286
|
+
eventTime,
|
|
287
|
+
it.type,
|
|
288
|
+
it.eventId,
|
|
289
|
+
(0, _operator_1.parseOperator)(it.operator).name || '—',
|
|
290
|
+
it.summary,
|
|
291
|
+
];
|
|
251
292
|
return isMultiTable ? [it.targetTable, ...cells] : cells;
|
|
252
293
|
});
|
|
253
294
|
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, rows) : (0, render_1.renderTsv)(headers, rows));
|
|
254
295
|
if (skipped.length > 0) {
|
|
255
|
-
process.stderr.write(
|
|
296
|
+
process.stderr.write(formatSkippedHint(skipped, tables.length) + '\n');
|
|
256
297
|
}
|
|
257
298
|
if (result.hasMore && result.nextCursor) {
|
|
258
299
|
process.stderr.write(`(more results; use --cursor '${result.nextCursor}')\n`);
|
|
@@ -278,6 +319,54 @@ function normalizeTime(input, flagName) {
|
|
|
278
319
|
throw err;
|
|
279
320
|
}
|
|
280
321
|
}
|
|
322
|
+
// PRD 41-48 行格式:`— Skipped 1 of 3 tables: orders (audit not enabled)`
|
|
323
|
+
// 服务端 skipped 数组是 audit 未启用的表(bare 名);上面 peel 循环拼出来的
|
|
324
|
+
// "<name> (table not found)" 已经自带 reason,t.includes('(') 走原样透传,bare 名
|
|
325
|
+
// 默认拼 "(audit not enabled)"。也兼容未来后端直接给带 reason 字符串的可能。
|
|
326
|
+
function formatSkippedHint(skipped, totalRequested) {
|
|
327
|
+
const items = skipped.map((t) => (t.includes('(') ? t : `${t} (audit not enabled)`)).join(', ');
|
|
328
|
+
return `— Skipped ${String(skipped.length)} of ${String(totalRequested)} tables: ${items}`;
|
|
329
|
+
}
|
|
330
|
+
// audit list 后端错误码加 hint:
|
|
331
|
+
// - k_dl_000005 表不存在 → 文案与 hint 对齐 `db schema get` 的统一格式
|
|
332
|
+
// - k_dl_1300040 单表 audit 未启用 → 指引 enable
|
|
333
|
+
// - k_dl_1300041 多表全部未启用 → 指引 status
|
|
334
|
+
function decorateAuditListError(err, tables) {
|
|
335
|
+
if (!(err instanceof error_1.AppError))
|
|
336
|
+
return err;
|
|
337
|
+
if (err.code === 'DB_API_k_dl_000005') {
|
|
338
|
+
// 不复用 dataloom 透传的 message(旧版/新版文案不一致:`table [x] not exist` /
|
|
339
|
+
// `table x not found`),统一改写成跟 schema get 一样的 `Table '<name>' does not exist`,
|
|
340
|
+
// 单表传 tables[0],多表场景兜底用解析到的 raw message 里第一个表名。
|
|
341
|
+
const t = tables.length > 0 ? tables[0] : (extractMissingTable(err.message) ?? '<table>');
|
|
342
|
+
return new error_1.AppError('TABLE_NOT_FOUND', `Table '${t}' does not exist`, {
|
|
343
|
+
next_actions: [`Did you mean another table? Run "miaoda db schema list" to see all tables.`],
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (err.code === 'DB_API_k_dl_1300040') {
|
|
347
|
+
const t = tables[0] ?? '<table>';
|
|
348
|
+
return new error_1.AppError(err.code, err.message, {
|
|
349
|
+
next_actions: [`Enable with: miaoda db audit enable ${t}`],
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (err.code === 'DB_API_k_dl_1300041') {
|
|
353
|
+
return new error_1.AppError(err.code, err.message, {
|
|
354
|
+
next_actions: ['Check audit status with: miaoda db audit status'],
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return err;
|
|
358
|
+
}
|
|
359
|
+
// extractMissingTable 从 dataloom 原始文案里抠表名兜底。dataloom 端有两种格式:
|
|
360
|
+
// - 旧版:`Table [foo] doesn't exist` / `table [foo] not exist`
|
|
361
|
+
// - 新版(本次 commits):`table foo not found`
|
|
362
|
+
// 都失配时返 null,调用方走 `<table>` 占位。
|
|
363
|
+
function extractMissingTable(msg) {
|
|
364
|
+
const bracket = /\[([^\]]+)\]/.exec(msg);
|
|
365
|
+
if (bracket)
|
|
366
|
+
return bracket[1];
|
|
367
|
+
const m = /table\s+([\w.]+)\s+not (?:exist|found)/i.exec(msg);
|
|
368
|
+
return m ? m[1] : null;
|
|
369
|
+
}
|
|
281
370
|
// 服务端 before/after 是 JSON 字符串透传,CLI JSON 输出再反序列化回对象,
|
|
282
371
|
// 给下游 jq 等工具消费。失败时透传原始字符串避免数据丢失。
|
|
283
372
|
function safeParseJson(s) {
|
|
@@ -40,11 +40,12 @@ const error_1 = require("../../../utils/error");
|
|
|
40
40
|
const output_1 = require("../../../utils/output");
|
|
41
41
|
const render_1 = require("../../../utils/render");
|
|
42
42
|
const time_1 = require("../../../utils/time");
|
|
43
|
+
const _operator_1 = require("../../../cli/handlers/db/_operator");
|
|
43
44
|
function toRow(it) {
|
|
44
45
|
return {
|
|
45
46
|
change_id: it.changeId,
|
|
46
47
|
changed_at: it.changedAt,
|
|
47
|
-
operator: it.operator,
|
|
48
|
+
operator: (0, _operator_1.parseOperator)(it.operator),
|
|
48
49
|
target_table: it.targetTable,
|
|
49
50
|
change_type: it.changeType,
|
|
50
51
|
summary: it.summary,
|
|
@@ -74,10 +75,17 @@ async function handleDbChangelog(opts) {
|
|
|
74
75
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
75
76
|
const since = normalizeTime(opts.since, '--since');
|
|
76
77
|
const until = normalizeTime(opts.until, '--until');
|
|
78
|
+
// --change-id 是精确单条查询,CLI 透传给后端;后端若暂未支持过滤,CLI 端
|
|
79
|
+
// 兜底翻页找命中项,保证 PRD 「最多返回一条」的语义稳定。
|
|
80
|
+
const trimmed = opts.changeId?.trim();
|
|
81
|
+
const changeId = trimmed !== undefined && trimmed !== '' ? trimmed : undefined;
|
|
77
82
|
const allItems = [];
|
|
78
83
|
let cursor = opts.cursor;
|
|
79
84
|
let lastCursor = null;
|
|
80
85
|
let lastHasMore = false;
|
|
86
|
+
// 指定 --change-id 时强制开 --all,确保即使后端不识别 changeId 过滤参数,
|
|
87
|
+
// CLI 也能翻完所有页找到目标记录(changelog 默认按时间倒序,一般在前几页)。
|
|
88
|
+
const allMode = opts.all === true || changeId !== undefined;
|
|
81
89
|
// --all:循环到 hasMore=false;否则只拉一页
|
|
82
90
|
// 没传 --all 时翻页由调用方自己用 --cursor 串
|
|
83
91
|
for (;;) {
|
|
@@ -86,6 +94,7 @@ async function handleDbChangelog(opts) {
|
|
|
86
94
|
table: opts.table,
|
|
87
95
|
since,
|
|
88
96
|
until,
|
|
97
|
+
changeId,
|
|
89
98
|
limit: opts.limit,
|
|
90
99
|
cursor,
|
|
91
100
|
dbBranch: opts.env,
|
|
@@ -93,14 +102,28 @@ async function handleDbChangelog(opts) {
|
|
|
93
102
|
allItems.push(...page.items);
|
|
94
103
|
lastCursor = page.nextCursor;
|
|
95
104
|
lastHasMore = page.hasMore;
|
|
96
|
-
if (!
|
|
105
|
+
if (!allMode || !page.hasMore || !page.nextCursor)
|
|
97
106
|
break;
|
|
98
107
|
cursor = page.nextCursor;
|
|
108
|
+
// 后端命中过滤返单条时提前退出,免得继续无意义翻页
|
|
109
|
+
if (changeId !== undefined && allItems.some((it) => it.changeId === changeId))
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
// CLI 端兜底过滤:把 changeId 匹配的项筛出来。后端如果已支持,列表本身就只有
|
|
113
|
+
// 0 或 1 条,filter 是恒等运算;后端未支持时通过翻页 + 此过滤拿到精确单条。
|
|
114
|
+
if (changeId !== undefined) {
|
|
115
|
+
const matched = allItems.filter((it) => it.changeId === changeId);
|
|
116
|
+
allItems.length = 0;
|
|
117
|
+
allItems.push(...matched);
|
|
118
|
+
// 精确查询语义:永远当作"已取完",不再透出分页 cursor / has_more
|
|
119
|
+
lastCursor = null;
|
|
120
|
+
lastHasMore = false;
|
|
99
121
|
}
|
|
100
122
|
if ((0, output_1.isJsonMode)()) {
|
|
101
123
|
const rows = allItems.map(toRow);
|
|
102
|
-
// --all 时已经把所有页合一起返,has_more=false / next_cursor=null
|
|
103
|
-
|
|
124
|
+
// --all 或 --change-id 时已经把所有页合一起返,has_more=false / next_cursor=null。
|
|
125
|
+
// PRD: --change-id 即使没命中(rows 长度 0)也保持 data 为数组。
|
|
126
|
+
if (allMode) {
|
|
104
127
|
(0, output_1.emitPaged)((0, output_1.snakeCaseKeys)(rows), null, false);
|
|
105
128
|
}
|
|
106
129
|
else {
|
|
@@ -109,22 +132,29 @@ async function handleDbChangelog(opts) {
|
|
|
109
132
|
return;
|
|
110
133
|
}
|
|
111
134
|
if (allItems.length === 0) {
|
|
112
|
-
|
|
135
|
+
// --change-id 没命中时单独报错,便于 agent 区分"无变更"和"ID 不存在"
|
|
136
|
+
if (changeId !== undefined) {
|
|
137
|
+
(0, output_1.emit)(`No DDL change with id=${changeId} found.`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
(0, output_1.emit)('No DDL changes found.');
|
|
141
|
+
}
|
|
113
142
|
return;
|
|
114
143
|
}
|
|
115
144
|
const tty = (0, render_1.isStdoutTty)();
|
|
116
145
|
// PRD: change_id / changed_at / operator / target_table / change_type / summary
|
|
117
146
|
const headers = ['change_id', 'changed_at', 'operator', 'target_table', 'change_type', 'summary'];
|
|
147
|
+
// pretty 渲染只展示 operator.name(兼容 PRD 原 string 形态);--json 走 toRow 输出完整对象
|
|
118
148
|
const rows = allItems.map((it) => [
|
|
119
149
|
it.changeId,
|
|
120
150
|
(0, render_1.formatTime)(it.changedAt, tty),
|
|
121
|
-
it.operator || '—',
|
|
151
|
+
(0, _operator_1.parseOperator)(it.operator).name || '—',
|
|
122
152
|
it.targetTable || '—',
|
|
123
153
|
it.changeType,
|
|
124
154
|
it.summary || '—',
|
|
125
155
|
]);
|
|
126
156
|
(0, output_1.emit)(tty ? (0, render_1.renderAlignedTable)(headers, rows) : (0, render_1.renderTsv)(headers, rows));
|
|
127
|
-
if (!
|
|
157
|
+
if (!allMode && lastHasMore && lastCursor) {
|
|
128
158
|
process.stderr.write(`(more results; use --cursor ${lastCursor} or --all)\n`);
|
|
129
159
|
}
|
|
130
160
|
}
|
|
@@ -32,14 +32,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.handleDbMigrationInit = handleDbMigrationInit;
|
|
40
37
|
exports.handleDbMigrationDiff = handleDbMigrationDiff;
|
|
41
38
|
exports.handleDbMigrationApply = handleDbMigrationApply;
|
|
42
|
-
const node_readline_1 = __importDefault(require("node:readline"));
|
|
43
39
|
const api = __importStar(require("../../../api/index"));
|
|
44
40
|
const shared_1 = require("../../../cli/commands/shared");
|
|
45
41
|
const colors_1 = require("../../../utils/colors");
|
|
@@ -47,17 +43,17 @@ const error_1 = require("../../../utils/error");
|
|
|
47
43
|
const output_1 = require("../../../utils/output");
|
|
48
44
|
const poll_1 = require("../../../utils/poll");
|
|
49
45
|
const render_1 = require("../../../utils/render");
|
|
46
|
+
const spinner_1 = require("../../../utils/spinner");
|
|
47
|
+
const _destructive_1 = require("../../../cli/handlers/db/_destructive");
|
|
50
48
|
async function handleDbMigrationInit(opts) {
|
|
51
49
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
50
|
+
// 不可逆操作:--yes 直接放行;非 TTY 抛 DESTRUCTIVE_REQUIRES_CONFIRM;TTY 交互确认。
|
|
51
|
+
// 不再用 isJsonMode() 做门 —— 见 _destructive.ts 注释。
|
|
52
|
+
const suffix = opts.syncData ? ' (existing data will be copied to dev)' : '';
|
|
53
|
+
const ok = await (0, _destructive_1.confirmDestructive)(`? This action is irreversible. Initialize multi-env (dev / online)${suffix}? (y/N) `, opts.yes);
|
|
54
|
+
if (!ok) {
|
|
55
|
+
(0, output_1.emit)('Aborted.');
|
|
56
|
+
return;
|
|
61
57
|
}
|
|
62
58
|
let result;
|
|
63
59
|
try {
|
|
@@ -88,12 +84,16 @@ async function handleDbMigrationInit(opts) {
|
|
|
88
84
|
async function handleDbMigrationDiff(opts) {
|
|
89
85
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
90
86
|
let result;
|
|
87
|
+
const stopSpinner = (0, spinner_1.startSpinner)('Previewing migration diff (dev → online)');
|
|
91
88
|
try {
|
|
92
89
|
result = await api.db.migrate({ appId, dryRun: true });
|
|
93
90
|
}
|
|
94
91
|
catch (err) {
|
|
95
92
|
throw decorateMigrationError(err);
|
|
96
93
|
}
|
|
94
|
+
finally {
|
|
95
|
+
stopSpinner();
|
|
96
|
+
}
|
|
97
97
|
// PRD: diff 在无待发布变更时报错带 hint,而不是渲染空列表
|
|
98
98
|
if (result.changes.length === 0) {
|
|
99
99
|
throw new error_1.AppError('DB_API_k_dl_1300035', `No pending changes between ${result.from} and ${result.to}`, {
|
|
@@ -106,15 +106,20 @@ async function handleDbMigrationDiff(opts) {
|
|
|
106
106
|
}
|
|
107
107
|
async function handleDbMigrationApply(opts) {
|
|
108
108
|
const appId = (0, shared_1.resolveAppId)(opts);
|
|
109
|
-
// TTY
|
|
110
|
-
if (
|
|
109
|
+
// --yes 跳过预览 + 确认;否则 TTY 拉 diff 给用户审,非 TTY 直接拒(避免无意义 dry-run RPC)
|
|
110
|
+
if (opts.yes !== true) {
|
|
111
|
+
(0, _destructive_1.assertDestructiveAllowedInTty)(opts.yes);
|
|
111
112
|
let preview;
|
|
113
|
+
const stopSpinner = (0, spinner_1.startSpinner)('Previewing migration diff (dev → online)');
|
|
112
114
|
try {
|
|
113
115
|
preview = await api.db.migrate({ appId, dryRun: true });
|
|
114
116
|
}
|
|
115
117
|
catch (err) {
|
|
116
118
|
throw decorateMigrationError(err);
|
|
117
119
|
}
|
|
120
|
+
finally {
|
|
121
|
+
stopSpinner();
|
|
122
|
+
}
|
|
118
123
|
if (preview.changes.length === 0) {
|
|
119
124
|
// PRD 文案 + hint
|
|
120
125
|
throw new error_1.AppError('DB_API_k_dl_1300035', `No pending changes between ${preview.from} and ${preview.to}`, {
|
|
@@ -123,8 +128,10 @@ async function handleDbMigrationApply(opts) {
|
|
|
123
128
|
],
|
|
124
129
|
});
|
|
125
130
|
}
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
// --json 模式跳过 pretty diff 渲染(污染 stdout envelope),但仍要求 confirm
|
|
132
|
+
if (!(0, output_1.isJsonMode)())
|
|
133
|
+
renderDiff(preview);
|
|
134
|
+
const ok = await (0, _destructive_1.askYesNo)(`? Apply ${String(preview.changes.length)} change(s) to ${preview.to}? (y/N) `);
|
|
128
135
|
if (!ok) {
|
|
129
136
|
(0, output_1.emit)('Aborted.');
|
|
130
137
|
return;
|
|
@@ -145,6 +152,7 @@ async function handleDbMigrationApply(opts) {
|
|
|
145
152
|
const taskId = result.taskId;
|
|
146
153
|
const final = await (0, poll_1.pollUntilDone)({
|
|
147
154
|
label: 'migration apply',
|
|
155
|
+
spinnerLabel: 'Applying migration (dev → online)',
|
|
148
156
|
intervalMs: 1000,
|
|
149
157
|
fetch: () => api.db.getMigrationStatus({ appId, taskId }),
|
|
150
158
|
isDone: (cur) => {
|
|
@@ -224,12 +232,3 @@ function decorateMigrationError(err) {
|
|
|
224
232
|
return err;
|
|
225
233
|
}
|
|
226
234
|
}
|
|
227
|
-
async function confirm(prompt) {
|
|
228
|
-
const rl = node_readline_1.default.createInterface({ input: process.stdin, output: process.stderr });
|
|
229
|
-
return new Promise((resolve) => {
|
|
230
|
-
rl.question(prompt, (answer) => {
|
|
231
|
-
rl.close();
|
|
232
|
-
resolve(answer.trim().toLowerCase() === 'y');
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
}
|