50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import * as dotenv from 'dotenv';
|
||
dotenv.config();
|
||
import pool from './src/config/database';
|
||
|
||
async function run() {
|
||
console.log('开始清理测试数据...');
|
||
|
||
// 1. 清理 AI 结果
|
||
const [ai] = await pool.query<any>('DELETE FROM ai_result');
|
||
console.log(`删除 ai_result: ${ai.affectedRows} 条`);
|
||
|
||
// 2. 清理操作日志
|
||
const [logs] = await pool.query<any>('DELETE FROM operation_log');
|
||
console.log(`删除 operation_log: ${logs.affectedRows} 条`);
|
||
|
||
// 3. 清理考勤数据
|
||
const [att] = await pool.query<any>('DELETE FROM attendance');
|
||
console.log(`删除 attendance: ${att.affectedRows} 条`);
|
||
|
||
// 4. 清理绩效项明细
|
||
const [items] = await pool.query<any>('DELETE FROM perf_item');
|
||
console.log(`删除 perf_item: ${items.affectedRows} 条`);
|
||
|
||
// 5. 清理绩效主表
|
||
const [perf] = await pool.query<any>('DELETE FROM performance_month');
|
||
console.log(`删除 performance_month: ${perf.affectedRows} 条`);
|
||
|
||
// 6. 清理测试员工账号(保留管理层和总经理账号)
|
||
const [users] = await pool.query<any>("DELETE FROM user WHERE role = 'employee'");
|
||
console.log(`删除测试员工账号: ${users.affectedRows} 条`);
|
||
|
||
// 重置自增ID
|
||
await pool.query('ALTER TABLE ai_result AUTO_INCREMENT = 1');
|
||
await pool.query('ALTER TABLE operation_log AUTO_INCREMENT = 1');
|
||
await pool.query('ALTER TABLE attendance AUTO_INCREMENT = 1');
|
||
await pool.query('ALTER TABLE perf_item AUTO_INCREMENT = 1');
|
||
await pool.query('ALTER TABLE performance_month AUTO_INCREMENT = 1');
|
||
await pool.query('ALTER TABLE user AUTO_INCREMENT = 1');
|
||
|
||
// 查看剩余账号
|
||
const [remaining] = await pool.query<any[]>('SELECT user_id, username, name, role FROM user ORDER BY role');
|
||
console.log('\n剩余账号:');
|
||
console.table(remaining);
|
||
|
||
await pool.end();
|
||
console.log('\n清理完成!');
|
||
}
|
||
|
||
run().catch(console.error);
|