-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-timestamps.js
More file actions
29 lines (23 loc) · 960 Bytes
/
Copy pathfix-timestamps.js
File metadata and controls
29 lines (23 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const db = require('./db');
// 查找无效时间戳的记录
const stmt = db.db.prepare('SELECT id, title, timestamp FROM news WHERE timestamp IS NULL OR timestamp <= 0 LIMIT 10');
const rows = stmt.all();
if (rows.length === 0) {
console.log('✓ 所有记录时间戳正常');
} else {
console.log(`发现 ${rows.length} 条记录时间戳无效:`);
rows.forEach(r => {
console.log(`ID ${r.id}: ts=${r.timestamp}, title=${r.title.substring(0, 50)}...`);
});
// 批量修复
const updateStmt = db.db.prepare('UPDATE news SET timestamp = ? WHERE id = ?');
const tx = db.db.transaction((records) => {
records.forEach(r => updateStmt.run(Date.now(), r.id));
});
tx(rows);
console.log(`\n✓ 已修复 ${rows.length} 条记录的时间戳`);
// 验证
const verify = db.db.prepare('SELECT COUNT(*) as n FROM news WHERE timestamp <= 0').get();
console.log(`✓ 剩余无效时间戳:${verify.n}`);
}
db.db.close();