72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
// 数据库文件路径
|
||
|
|
const dbPath = path.join(__dirname, 'company_finance.db');
|
||
|
|
|
||
|
|
// 连接数据库
|
||
|
|
const db = new sqlite3.Database(dbPath, (err) => {
|
||
|
|
if (err) {
|
||
|
|
console.error('数据库连接失败:', err.message);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
console.log('SQLite数据库连接成功');
|
||
|
|
clearData();
|
||
|
|
});
|
||
|
|
|
||
|
|
// 清除数据的函数
|
||
|
|
function clearData() {
|
||
|
|
console.log('开始清除除合作伙伴、商品分类和商品外的所有数据...');
|
||
|
|
|
||
|
|
// 需要保留的表
|
||
|
|
const tablesToKeep = ['suppliers', 'product_categories', 'products'];
|
||
|
|
|
||
|
|
// 需要清除的表(根据常见的ERP系统表结构)
|
||
|
|
const tablesToClear = [
|
||
|
|
'purchase_requests',
|
||
|
|
'purchase_request_items',
|
||
|
|
'inventory_records',
|
||
|
|
'payment_requests',
|
||
|
|
'expense_claims',
|
||
|
|
'expense_claim_details',
|
||
|
|
'projects',
|
||
|
|
'customers',
|
||
|
|
'subcontractors',
|
||
|
|
'quotations',
|
||
|
|
'quotation_items',
|
||
|
|
'contracts',
|
||
|
|
'payment_terms',
|
||
|
|
'advances',
|
||
|
|
'reimbursements',
|
||
|
|
'financial_records',
|
||
|
|
'financial_transactions',
|
||
|
|
'vouchers',
|
||
|
|
'exchange_rates',
|
||
|
|
'users',
|
||
|
|
'roles',
|
||
|
|
'permissions'
|
||
|
|
];
|
||
|
|
|
||
|
|
// 执行清除操作
|
||
|
|
let completed = 0;
|
||
|
|
const total = tablesToClear.length;
|
||
|
|
|
||
|
|
tablesToClear.forEach(table => {
|
||
|
|
db.run(`DELETE FROM ${table}`, (err) => {
|
||
|
|
if (err) {
|
||
|
|
console.warn(`清除${table}表数据失败:`, err.message);
|
||
|
|
} else {
|
||
|
|
console.log(`✓ 已清除${table}表数据`);
|
||
|
|
}
|
||
|
|
|
||
|
|
completed++;
|
||
|
|
if (completed === total) {
|
||
|
|
console.log('\n数据清除完成!');
|
||
|
|
console.log('已保留以下表的数据:');
|
||
|
|
tablesToKeep.forEach(table => console.log(`- ${table}`));
|
||
|
|
db.close();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|