冰朔 8743426ed0
Some checks failed
自动更新代码和重启 / update-and-restart (push) Has been cancelled
CI检查 + 自动部署 / check (push) Has been cancelled
CI检查 + 自动部署 / deploy (push) Has been cancelled
persona-brain-db 搬家: repo根→brain/fifth-domain/zero-point/zhuyuan/persona-brain-db/ · 零点原核子模块归位 · 删旧副本·cognitive-index新增
2026-06-04 21:10:05 +08:00

52 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 双写模式工具
* Phase 2/3 启用
*
* 功能:新数据同时写入 Notion + persona-brain-db
* 确保数据一致性支持从Notion主→persona-brain-db主的渐进切换
*/
/**
* 双写同时写入Notion和persona-brain-db
* @param {string} table - 目标表名
* @param {object} data - 写入数据
* @param {object} options - 配置选项
*/
async function dualWrite(table, data, options = {}) {
const { notionClient, brainDbClient, primarySource = 'notion' } = options;
console.log(`📝 双写模式 [${primarySource}为主] → ${table}`);
const results = { notion: null, brainDb: null, errors: [] };
// 写入主数据源
try {
if (primarySource === 'notion') {
results.notion = await writeToNotion(notionClient, table, data);
results.brainDb = await writeToBrainDb(brainDbClient, table, data);
} else {
results.brainDb = await writeToBrainDb(brainDbClient, table, data);
results.notion = await writeToNotion(notionClient, table, data);
}
} catch (err) {
results.errors.push(err.message);
console.error(`❌ 双写失败: ${err.message}`);
}
return results;
}
async function writeToNotion(client, table, data) {
// Phase 2/3 实现
console.log(` → Notion写入 [${table}]: 占位`);
return { status: 'placeholder' };
}
async function writeToBrainDb(client, table, data) {
// Phase 2/3 实现
console.log(` → BrainDB写入 [${table}]: 占位`);
return { status: 'placeholder' };
}
module.exports = { dualWrite };