Files
Toolbox/dev_test_scripts/debug/diag_birthday_sql.js
T
yangxiangyuan db7648eb4d feat(mp, web, calendar): 新增微信收藏夹与日历批量生成功能
- 新增微信小程序版个人收藏夹全套功能,包含聚合首页、收藏列表、编辑、详情页面与配套后端API
- 新增web版时光助手门户与个人收藏夹工具,支持与小程序共享后端数据
- 优化日历提醒工具:替换本地bootstrap资源为公共CDN版本,新增批量生成循环提醒的前端界面与后端逻辑,新增数据库batch_id字段,更新鉴权配置文件
- 补充项目配置、站点地图、调试诊断脚本等配套文件
- 完善各模块的页面配置与样式文件
2026-09-02 22:20:37 +08:00

47 lines
2.7 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.
// 只读诊断:用户刚执行的 16 条家人生日 SQL 是否真的入库
// 用法:node dev_test_scripts/debug/diag_birthday_sql.js
const path = require('path')
const fs = require('fs')
const Database = require('better-sqlite3')
const DB_PATH = path.join(process.cwd(), 'data', 'calendar_reminder.db')
if (!fs.existsSync(DB_PATH)) { console.error('DB NOT FOUND:', DB_PATH); process.exit(2) }
const db = new Database(DB_PATH, { readonly: true, fileMustExist: true })
console.log('=== 1. 最近 5 个 calendar_batches(找 sql_ 前缀最新批次) ===')
const batches = db.prepare(`SELECT id,title,status,params_json,generated_count,inserted_count,dedup_count,rollback_count,created_at,updated_at
FROM calendar_batches ORDER BY rowid DESC LIMIT 5`).all()
for (const b of batches) {
const p = b.params_json ? JSON.parse(b.params_json) : null
console.log(` - [${b.id}] ${b.title} | status=${b.status} | gen=${b.generated_count} ins=${b.inserted_count} dedup=${b.dedup_count} rb=${b.rollback_count} | created=${b.created_at} | range=${p && p.rangeStart}~${p && p.rangeEnd} | source=${p && p.source}`)
}
console.log('\n=== 2. 搜索 16 条 id 前缀的事件(bd_fa_ / bd_mo_ / bd_si_ / bd_me_) ===')
const prefixes = ['bd_fa_', 'bd_mo_', 'bd_si_', 'bd_me_']
const like = prefixes.map(p => `id LIKE '${p}%'`).join(' OR ')
const rows = db.prepare(`SELECT id,title,start,end,allDay,remindAt,deleted,completed,batch_id FROM events
WHERE ${like} ORDER BY start ASC`).all()
console.log(` 命中 ${rows.length} 行(期望 16)`)
for (const r of rows) {
console.log(` - [${r.id.slice(0,32)}...] ${r.title} | ${r.start} ~ ${r.end} | allDay=${r.allDay} remindAt=${r.remindAt} | deleted=${r.deleted} done=${r.completed} | batch=${r.batch_id}`)
}
if (rows.length === 16) {
const byY = {}
for (const r of rows) { const y = r.start.slice(0,4); byY[y] = (byY[y]||0)+1 }
console.log(' 按年分布:', JSON.stringify(byY))
const missingRemind = rows.filter(r => !r.remindAt)
console.log(' 未设置提醒(期望 0):', missingRemind.length)
const notAllDay = rows.filter(r => r.allDay != 1)
console.log(' 非全天事件(期望 0):', notAllDay.length)
const deletedOnes = rows.filter(r => r.deleted != 0)
console.log(' 已逻辑删除(期望 0):', deletedOnes.length)
const batch_ids = [...new Set(rows.filter(r => r.batch_id).map(r => r.batch_id))]
console.log(' 关联 batch_id 集合(期望 1 个 sql_ 前缀):', batch_ids)
}
console.log('\n=== 3. 时间跨度 sanity check(期望 start∈[2027-06-15, 2030-12-01]) ===')
const span = db.prepare(`SELECT MIN(start) min_s, MAX(end) max_e FROM events WHERE ${like}`).get()
console.log(' min start =', span.min_s, ' | max end =', span.max_e)