43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|||
|
|
const db = new sqlite3.Database('company_finance.db');
|
||
|
|
|
||
|
|
// 更新执行记录表,添加 voucher_files 字段
|
||
|
|
db.serialize(() => {
|
||
|
|
console.log('开始更新执行记录表...');
|
||
|
|
|
||
|
|
// 检查 voucher_files 字段是否存在
|
||
|
|
db.all("PRAGMA table_info(executions)", (err, rows) => {
|
||
|
|
if (err) {
|
||
|
|
console.error('获取表结构失败:', err.message);
|
||
|
|
db.close();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const hasVoucherFiles = rows.some(row => row.name === 'voucher_files');
|
||
|
|
|
||
|
|
if (!hasVoucherFiles) {
|
||
|
|
// 添加 voucher_files 字段
|
||
|
|
db.run(`ALTER TABLE executions ADD COLUMN voucher_files TEXT`, (err) => {
|
||
|
|
if (err) {
|
||
|
|
console.error('添加 voucher_files 字段失败:', err.message);
|
||
|
|
} else {
|
||
|
|
console.log('✓ voucher_files 字段添加成功');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
console.log('✓ voucher_files 字段已存在');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 关闭数据库连接
|
||
|
|
setTimeout(() => {
|
||
|
|
db.close((err) => {
|
||
|
|
if (err) {
|
||
|
|
console.error('关闭数据库失败:', err.message);
|
||
|
|
} else {
|
||
|
|
console.log('数据库连接已关闭');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}, 100);
|
||
|
|
});
|
||
|
|
});
|