备份:修复前完整项目快照 2026-04-19
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
const db = require('./backend/db-sqlite');
|
||||
async function fix() {
|
||||
const fixes = [
|
||||
// Missing table for logistics delete
|
||||
`CREATE TABLE IF NOT EXISTS logistics_company_payment_infos (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
logistics_company_id INTEGER,
|
||||
bank_name TEXT DEFAULT '',
|
||||
account_name TEXT DEFAULT '',
|
||||
account_number TEXT DEFAULT '',
|
||||
is_default INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)`,
|
||||
|
||||
// return_records - missing return_type column
|
||||
"ALTER TABLE return_records ADD COLUMN return_type TEXT DEFAULT ''",
|
||||
|
||||
// payment_plans - make purchase_order_id nullable by recreating
|
||||
// Instead, let's add a default value approach - we need to check the table
|
||||
// Actually, we can't change NOT NULL constraint in SQLite.
|
||||
// Let's just provide purchase_order_id in test data instead.
|
||||
|
||||
// Projects - check what's needed
|
||||
"ALTER TABLE projects ADD COLUMN category TEXT DEFAULT ''",
|
||||
"ALTER TABLE projects ADD COLUMN location TEXT DEFAULT ''",
|
||||
"ALTER TABLE projects ADD COLUMN client_name TEXT DEFAULT ''",
|
||||
|
||||
// Exchange rates - add effective_date
|
||||
"ALTER TABLE exchange_rates ADD COLUMN effective_date TEXT DEFAULT ''",
|
||||
"ALTER TABLE exchange_rates ADD COLUMN base_currency TEXT DEFAULT 'CNY'",
|
||||
|
||||
// Budget projects - add more columns
|
||||
"ALTER TABLE budget_projects ADD COLUMN project_code TEXT DEFAULT ''",
|
||||
"ALTER TABLE budget_projects ADD COLUMN category TEXT DEFAULT ''",
|
||||
"ALTER TABLE budget_projects ADD COLUMN client TEXT DEFAULT ''",
|
||||
|
||||
// Returns - add more columns
|
||||
"ALTER TABLE returns ADD COLUMN return_type TEXT DEFAULT ''",
|
||||
"ALTER TABLE returns ADD COLUMN warehouse TEXT DEFAULT ''",
|
||||
"ALTER TABLE returns ADD COLUMN handler TEXT DEFAULT ''",
|
||||
"ALTER TABLE returns ADD COLUMN return_date TEXT DEFAULT ''",
|
||||
];
|
||||
|
||||
for (const sql of fixes) {
|
||||
try {
|
||||
await db.query(sql);
|
||||
console.log('OK:', sql.substring(0, 70));
|
||||
} catch(e) {
|
||||
const msg = e.message || '';
|
||||
if (msg.includes('duplicate') || msg.includes('already exists')) {
|
||||
console.log('SKIP:', sql.substring(0, 70));
|
||||
} else {
|
||||
console.log('ERR:', msg.substring(0, 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix payment_plans NOT NULL constraint - recreate table
|
||||
try {
|
||||
console.log('\n--- Fixing payment_plans table ---');
|
||||
await db.query(`CREATE TABLE IF NOT EXISTS payment_plans_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
purchase_order_id INTEGER DEFAULT 0,
|
||||
name TEXT DEFAULT '',
|
||||
amount REAL DEFAULT 0,
|
||||
payee TEXT DEFAULT '',
|
||||
payer TEXT DEFAULT '',
|
||||
planned_date TEXT DEFAULT '',
|
||||
actual_date TEXT DEFAULT '',
|
||||
status TEXT DEFAULT 'pending',
|
||||
description TEXT DEFAULT '',
|
||||
remark TEXT DEFAULT '',
|
||||
currency TEXT DEFAULT 'CNY',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)`);
|
||||
await db.query(`INSERT OR IGNORE INTO payment_plans_new SELECT * FROM payment_plans`);
|
||||
await db.query(`DROP TABLE payment_plans`);
|
||||
await db.query(`ALTER TABLE payment_plans_new RENAME TO payment_plans`);
|
||||
console.log('OK: payment_plans table recreated');
|
||||
} catch(e) {
|
||||
console.log('ERR payment_plans:', e.message.substring(0, 100));
|
||||
}
|
||||
|
||||
console.log('\nFinal round fixes applied!');
|
||||
process.exit();
|
||||
}
|
||||
fix();
|
||||
Reference in New Issue
Block a user