70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
|
|
// 简单的迁移工具测试
|
|||
|
|
const axios = require('axios');
|
|||
|
|
|
|||
|
|
async function testSimpleMigration() {
|
|||
|
|
const baseURL = 'http://localhost:3000';
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
console.log('🚀 开始测试迁移工具...\n');
|
|||
|
|
|
|||
|
|
// 等待应用启动
|
|||
|
|
console.log('⏳ 等待应用启动...');
|
|||
|
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|||
|
|
|
|||
|
|
// 测试健康检查
|
|||
|
|
console.log('🏥 检查应用健康状态...');
|
|||
|
|
try {
|
|||
|
|
const healthResponse = await axios.get(`${baseURL}/health`);
|
|||
|
|
console.log('✅ 应用健康状态:', healthResponse.status);
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log('⚠️ 健康检查失败,继续测试...');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 测试获取表列表
|
|||
|
|
console.log('\n📋 获取数据库表列表...');
|
|||
|
|
try {
|
|||
|
|
const tablesResponse = await axios.get(`${baseURL}/adminapi/migration/tables`);
|
|||
|
|
console.log('✅ 表列表获取成功');
|
|||
|
|
console.log('📊 表数量:', tablesResponse.data.data?.length || 0);
|
|||
|
|
|
|||
|
|
if (tablesResponse.data.data?.length > 0) {
|
|||
|
|
console.log('📝 前5个表:', tablesResponse.data.data.slice(0, 5));
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log('❌ 获取表列表失败:', error.response?.data?.message || error.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 测试预览代码生成
|
|||
|
|
console.log('\n👁️ 测试代码预览...');
|
|||
|
|
try {
|
|||
|
|
const previewResponse = await axios.post(`${baseURL}/adminapi/migration/preview`, {
|
|||
|
|
tableName: 'sys_user',
|
|||
|
|
generateController: true,
|
|||
|
|
generateService: true,
|
|||
|
|
generateEntity: true,
|
|||
|
|
generateDto: true
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log('✅ 代码预览成功');
|
|||
|
|
console.log('📁 生成文件数量:', previewResponse.data.data?.length || 0);
|
|||
|
|
|
|||
|
|
if (previewResponse.data.data?.length > 0) {
|
|||
|
|
console.log('📄 生成的文件:');
|
|||
|
|
previewResponse.data.data.forEach((file, index) => {
|
|||
|
|
console.log(` ${index + 1}. ${file.filePath} (${file.type})`);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.log('❌ 代码预览失败:', error.response?.data?.message || error.message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('\n🎉 测试完成!');
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 测试失败:', error.message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 运行测试
|
|||
|
|
testSimpleMigration();
|