39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import path from 'path';
|
|
import fs from 'fs';
|
|
import { getSystemDbPath, getUserDbPath } from './path.js';
|
|
|
|
// 迁移数据库文件
|
|
export async function migrateDatabases() {
|
|
// 开发环境下不执行迁移
|
|
if (process.env.NODE_ENV === 'development') {
|
|
console.log('开发环境下不执行数据库迁移');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// 确保数据目录存在
|
|
const systemDbPath = getSystemDbPath();
|
|
const userDbPath = getUserDbPath();
|
|
const dataDir = path.dirname(systemDbPath);
|
|
|
|
if (!fs.existsSync(dataDir)) {
|
|
fs.mkdirSync(dataDir, { recursive: true });
|
|
console.log(`创建数据目录: ${dataDir}`);
|
|
}
|
|
|
|
// 检查数据库文件是否存在
|
|
if (fs.existsSync(systemDbPath)) {
|
|
console.log(`系统数据库已存在: ${systemDbPath}`);
|
|
} else {
|
|
console.log(`系统数据库不存在: ${systemDbPath}`);
|
|
}
|
|
|
|
if (fs.existsSync(userDbPath)) {
|
|
console.log(`用户数据库已存在: ${userDbPath}`);
|
|
} else {
|
|
console.log(`用户数据库不存在: ${userDbPath}`);
|
|
}
|
|
} catch (error) {
|
|
console.error('数据库迁移检查失败:', error);
|
|
}
|
|
} |