添加db_migrate功能

This commit is contained in:
CN-JS-HuiBai
2026-04-22 21:24:43 +08:00
parent ce739d1232
commit 1430ecf366
4 changed files with 9 additions and 8 deletions

View File

@@ -6,7 +6,8 @@
"scripts": {
"dev": "node server/index.js",
"start": "node server/index.js",
"init-db": "node server/init-db.js"
"init-db": "node server/init-db.js",
"db-migrate": "node server/init-db.js"
},
"dependencies": {
"axios": "^1.7.0",

View File

@@ -204,7 +204,7 @@ async function ensureTable(tableName, tableSchema) {
}
}
async function checkAndFixDatabase() {
async function db_migrate() {
console.log('[Database Integrity] Starting comprehensive database audit...');
// Try to check if we can even connect
@@ -233,4 +233,4 @@ async function checkAndFixDatabase() {
}
}
module.exports = checkAndFixDatabase;
module.exports = db_migrate;

View File

@@ -7,7 +7,7 @@ const prometheusService = require('./prometheus-service');
const cache = require('./cache');
const geoService = require('./geo-service');
const latencyService = require('./latency-service');
const checkAndFixDatabase = require('./db-schema-check');
const db_migrate = require('./db-schema-check');
const http = require('http');
const WebSocket = require('ws');
const net = require('net');
@@ -651,7 +651,7 @@ APP_SECRET=${process.env.APP_SECRET || APP_SECRET}
cache.init();
// Run the migration/centralized schema tool to create/fix all tables
await checkAndFixDatabase();
await db_migrate();
isDbInitialized = true;
res.json({ success: true, message: 'Initialization complete' });
@@ -1509,7 +1509,7 @@ async function start() {
// 2. Automated repair/migration
try {
const dbFixed = await checkAndFixDatabase();
const dbFixed = await db_migrate();
if (dbFixed) {
// Refresh state after fix
await checkDb();

View File

@@ -1,7 +1,7 @@
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
const mysql = require('mysql2/promise');
const checkAndFixDatabase = require('./db-schema-check');
const db_migrate = require('./db-schema-check');
const db = require('./db');
async function initDatabase() {
@@ -31,7 +31,7 @@ async function initDatabase() {
// 3. Use the centralized schema tool to create/fix all tables
console.log(' 📦 Initializing tables using schema-check tool...');
await checkAndFixDatabase();
await db_migrate();
console.log(' ✅ Tables and columns ready');
console.log('\n🎉 Database initialization complete!\n');