添加db_migrate功能
This commit is contained in:
@@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node server/index.js",
|
"dev": "node server/index.js",
|
||||||
"start": "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": {
|
"dependencies": {
|
||||||
"axios": "^1.7.0",
|
"axios": "^1.7.0",
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ async function ensureTable(tableName, tableSchema) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkAndFixDatabase() {
|
async function db_migrate() {
|
||||||
console.log('[Database Integrity] Starting comprehensive database audit...');
|
console.log('[Database Integrity] Starting comprehensive database audit...');
|
||||||
|
|
||||||
// Try to check if we can even connect
|
// Try to check if we can even connect
|
||||||
@@ -233,4 +233,4 @@ async function checkAndFixDatabase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = checkAndFixDatabase;
|
module.exports = db_migrate;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const prometheusService = require('./prometheus-service');
|
|||||||
const cache = require('./cache');
|
const cache = require('./cache');
|
||||||
const geoService = require('./geo-service');
|
const geoService = require('./geo-service');
|
||||||
const latencyService = require('./latency-service');
|
const latencyService = require('./latency-service');
|
||||||
const checkAndFixDatabase = require('./db-schema-check');
|
const db_migrate = require('./db-schema-check');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
@@ -651,7 +651,7 @@ APP_SECRET=${process.env.APP_SECRET || APP_SECRET}
|
|||||||
cache.init();
|
cache.init();
|
||||||
|
|
||||||
// Run the migration/centralized schema tool to create/fix all tables
|
// Run the migration/centralized schema tool to create/fix all tables
|
||||||
await checkAndFixDatabase();
|
await db_migrate();
|
||||||
|
|
||||||
isDbInitialized = true;
|
isDbInitialized = true;
|
||||||
res.json({ success: true, message: 'Initialization complete' });
|
res.json({ success: true, message: 'Initialization complete' });
|
||||||
@@ -1509,7 +1509,7 @@ async function start() {
|
|||||||
|
|
||||||
// 2. Automated repair/migration
|
// 2. Automated repair/migration
|
||||||
try {
|
try {
|
||||||
const dbFixed = await checkAndFixDatabase();
|
const dbFixed = await db_migrate();
|
||||||
if (dbFixed) {
|
if (dbFixed) {
|
||||||
// Refresh state after fix
|
// Refresh state after fix
|
||||||
await checkDb();
|
await checkDb();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
|
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
|
||||||
const mysql = require('mysql2/promise');
|
const mysql = require('mysql2/promise');
|
||||||
const checkAndFixDatabase = require('./db-schema-check');
|
const db_migrate = require('./db-schema-check');
|
||||||
const db = require('./db');
|
const db = require('./db');
|
||||||
|
|
||||||
async function initDatabase() {
|
async function initDatabase() {
|
||||||
@@ -31,7 +31,7 @@ async function initDatabase() {
|
|||||||
|
|
||||||
// 3. Use the centralized schema tool to create/fix all tables
|
// 3. Use the centralized schema tool to create/fix all tables
|
||||||
console.log(' 📦 Initializing tables using schema-check tool...');
|
console.log(' 📦 Initializing tables using schema-check tool...');
|
||||||
await checkAndFixDatabase();
|
await db_migrate();
|
||||||
console.log(' ✅ Tables and columns ready');
|
console.log(' ✅ Tables and columns ready');
|
||||||
|
|
||||||
console.log('\n🎉 Database initialization complete!\n');
|
console.log('\n🎉 Database initialization complete!\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user