优化数据库自检
This commit is contained in:
@@ -305,15 +305,26 @@ function getCookie(req, name) {
|
||||
return matches ? decodeURIComponent(matches[1]) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database Initialization Check
|
||||
*/
|
||||
let isDbInitialized = false;
|
||||
async function checkDb() {
|
||||
try {
|
||||
const fs = require('fs');
|
||||
if (!fs.existsSync(path.join(__dirname, '..', '.env'))) {
|
||||
// In Docker or high-level environments, .env might not exist but process.env is set
|
||||
const hasConfig = process.env.MYSQL_HOST || fs.existsSync(path.join(__dirname, '..', '.env'));
|
||||
|
||||
if (!hasConfig) {
|
||||
isDbInitialized = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for essential tables
|
||||
const [rows] = await db.query("SHOW TABLES LIKE 'prometheus_sources'");
|
||||
isDbInitialized = rows.length > 0;
|
||||
const [rows2] = await db.query("SHOW TABLES LIKE 'site_settings'");
|
||||
|
||||
isDbInitialized = rows.length > 0 && rows2.length > 0;
|
||||
} catch (err) {
|
||||
isDbInitialized = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user