d58dc2a251
Introduce Draft → Confirm → Commit flow for WeChat schedule intents behind feature flags, plus h5_tasks dual-write/read aggregation and rollout scripts so reminders and automations get explicit user confirmation before persisting. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* 唐用户(103)legacy 任务 → h5_tasks 回填 + 对账
|
||
*
|
||
* 用法:
|
||
* node scripts/migrate-tang-unified-tasks-103.mjs
|
||
* node scripts/migrate-tang-unified-tasks-103.mjs --apply
|
||
*/
|
||
import process from 'node:process';
|
||
import mysql from 'mysql2/promise';
|
||
import { initSchema } from '../db.mjs';
|
||
import { createTaskUnifiedService, formatUnifiedTaskListReply } from '../task-unified-service.mjs';
|
||
import { loadH5Environment } from './load-env.mjs';
|
||
|
||
loadH5Environment(import.meta.dirname);
|
||
|
||
const TANG = 'a70ff537-8908-486e-9b6c-042e07cc25db';
|
||
|
||
async function main() {
|
||
const apply = process.argv.includes('--apply');
|
||
if (!process.env.DATABASE_URL) {
|
||
console.error('缺少 DATABASE_URL');
|
||
process.exit(1);
|
||
}
|
||
|
||
const pool = mysql.createPool({ uri: process.env.DATABASE_URL, connectionLimit: 2 });
|
||
await initSchema(pool);
|
||
const service = createTaskUnifiedService(pool);
|
||
|
||
const before = await service.listUserTasks({ userId: TANG, limit: 20 });
|
||
const migration = await service.migrateLegacyTasks({ userId: TANG, dryRun: !apply });
|
||
const after = apply
|
||
? await service.listUserTasks({ userId: TANG, limit: 20 })
|
||
: before;
|
||
|
||
const [storedCountRows] = await pool.query(
|
||
`SELECT COUNT(*) AS cnt FROM h5_tasks WHERE user_id = ? AND status = 'active'`,
|
||
[TANG],
|
||
);
|
||
|
||
console.log(JSON.stringify({
|
||
userId: TANG,
|
||
apply,
|
||
migration,
|
||
storedActiveCount: Number(storedCountRows?.[0]?.cnt ?? 0),
|
||
unifiedListPreview: formatUnifiedTaskListReply(after).split('\n').slice(0, 12),
|
||
tasks: after.map((task) => ({
|
||
type: task.type,
|
||
title: task.title,
|
||
legacyRef: task.legacyRef,
|
||
nextRunAt: task.nextRunAt,
|
||
})),
|
||
}, null, 2));
|
||
|
||
await pool.end();
|
||
}
|
||
|
||
main().catch((err) => {
|
||
console.error(err);
|
||
process.exit(1);
|
||
});
|