28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
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();
|
|
}
|