新增项目数据库自检流程

This commit is contained in:
CN-JS-HuiBai
2026-04-10 23:44:46 +08:00
parent 7362bcf206
commit 3519003a77
2 changed files with 18 additions and 3 deletions

View File

@@ -235,15 +235,21 @@ async function ensureTable(tableName, tableSchema) {
}
async function checkAndFixDatabase() {
const envPath = path.join(__dirname, '..', '.env');
if (!fs.existsSync(envPath)) return;
// Check for DB host to see if we have configuration (could be in .env or environment)
if (!process.env.MYSQL_HOST && !fs.existsSync(path.join(__dirname, '..', '.env'))) {
console.log('[Database Integrity] No configuration found, skipping check.');
return false;
}
try {
for (const [tableName, tableSchema] of Object.entries(SCHEMA)) {
await ensureTable(tableName, tableSchema);
}
return true;
} catch (err) {
console.error('[Database Integrity] Startup schema check failed:', err.message);
// Rethrow to allow caller to decide if this is fatal
throw err;
}
}