-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-data.js
More file actions
27 lines (22 loc) · 916 Bytes
/
fix-data.js
File metadata and controls
27 lines (22 loc) · 916 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
const { getDb, dbGet, dbAll, dbRun, persistDb, generateAccountNumber } = require('./src/database/db');
async function fixData() {
console.log('🔧 Fixing user data...');
const db = await getDb();
const users = await dbAll(db, 'SELECT id, username, phone, account_number FROM users');
for (const user of users) {
if (!user.account_number) {
const acctNum = await generateAccountNumber(db);
console.log(` Assigning ${acctNum} to ${user.username} (${user.phone})`);
await dbRun(db, 'UPDATE users SET account_number = ? WHERE id = ?', [acctNum, user.id]);
} else {
console.log(` User ${user.username} already has account number ${user.account_number}`);
}
}
persistDb(db);
console.log('✅ Done!');
process.exit(0);
}
fixData().catch(err => {
console.error('❌ Error:', err);
process.exit(1);
});