fix: apply quota point conversion
This commit is contained in:
1 parent
2553e482a9
commit
ad66ae5f10
12 files changed
+205
-25
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { db, initializeDatabase } from "../src/db";
|
||||
import { closeExternalDatabase, repairLegacyQuotaMappings } from "../src/external-db";
|
||||
|
||||
await initializeDatabase();
|
||||
|
||||
try {
|
||||
const rows = db.query(`SELECT id, user_id, points, refund_points, refund_points_enabled
|
||||
FROM orders
|
||||
WHERE user_id IS NOT NULL AND user_id <> ''
|
||||
AND (points_credited=1 OR refund_status='success' OR status='refunded')`).all() as Array<{
|
||||
id: string;
|
||||
user_id: string;
|
||||
points: number;
|
||||
refund_points: number;
|
||||
refund_points_enabled: number;
|
||||
}>;
|
||||
const result = await repairLegacyQuotaMappings(rows.map((row) => ({
|
||||
orderId: String(row.id),
|
||||
userId: String(row.user_id),
|
||||
points: Number(row.points || 0),
|
||||
refundPoints: row.refund_points_enabled ? Number(row.refund_points || 0) : 0
|
||||
})));
|
||||
console.log(`quota 映射迁移完成:修复入账 ${result.creditsRepaired} 条,修复退款 ${result.refundsRepaired} 条。`);
|
||||
} finally {
|
||||
await closeExternalDatabase();
|
||||
db.close();
|
||||
}
|
||||
Reference in new issue
Block a user