83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
|
|
const mysql = require('mysql2/promise');
|
||
|
|
|
||
|
|
// 数据库连接配置
|
||
|
|
const dbConfig = {
|
||
|
|
host: 'gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com',
|
||
|
|
port: 24936,
|
||
|
|
user: 'root',
|
||
|
|
password: '!Rjb12191',
|
||
|
|
database: 'pronode_db',
|
||
|
|
charset: 'utf8mb4'
|
||
|
|
};
|
||
|
|
|
||
|
|
async function verifyData() {
|
||
|
|
let connection;
|
||
|
|
|
||
|
|
try {
|
||
|
|
console.log('🔌 正在连接腾讯云数据库...');
|
||
|
|
|
||
|
|
// 创建连接
|
||
|
|
connection = await mysql.createConnection(dbConfig);
|
||
|
|
|
||
|
|
console.log('✅ 数据库连接成功!');
|
||
|
|
|
||
|
|
// 使用数据库
|
||
|
|
await connection.query('USE pronode_db');
|
||
|
|
console.log('✅ 已切换到 pronode_db 数据库');
|
||
|
|
|
||
|
|
// 验证用户数据
|
||
|
|
console.log('👥 验证用户数据...');
|
||
|
|
const [users] = await connection.query('SELECT id, email, name, createdAt FROM promptforge_users');
|
||
|
|
console.log(`✅ 找到 ${users.length} 个用户:`);
|
||
|
|
users.forEach(user => {
|
||
|
|
console.log(` - ${user.name} (${user.email}) - 创建于 ${user.createdAt}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 验证模板数据
|
||
|
|
console.log('📝 验证模板数据...');
|
||
|
|
const [templates] = await connection.query('SELECT id, title, category, rating, usageCount FROM promptforge_templates');
|
||
|
|
console.log(`✅ 找到 ${templates.length} 个模板:`);
|
||
|
|
templates.forEach(template => {
|
||
|
|
console.log(` - ${template.title} (${template.category}) - 评分: ${template.rating} - 使用次数: ${template.usageCount}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 验证系统配置
|
||
|
|
console.log('⚙️ 验证系统配置...');
|
||
|
|
const [configs] = await connection.query('SELECT config_key, value, type FROM promptforge_configs');
|
||
|
|
console.log(`✅ 找到 ${configs.length} 个配置项:`);
|
||
|
|
configs.forEach(config => {
|
||
|
|
console.log(` - ${config.config_key}: ${config.value} (${config.type})`);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 显示表结构
|
||
|
|
console.log('📊 数据库表结构概览...');
|
||
|
|
const [tables] = await connection.query("SHOW TABLES LIKE 'promptforge_%'");
|
||
|
|
console.log('📋 PromptForge 相关表:');
|
||
|
|
tables.forEach(table => {
|
||
|
|
console.log(` - ${Object.values(table)[0]}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('🎉 数据验证完成!');
|
||
|
|
return true;
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ 数据验证失败:', error.message);
|
||
|
|
return false;
|
||
|
|
} finally {
|
||
|
|
if (connection) {
|
||
|
|
await connection.end();
|
||
|
|
console.log('🔌 数据库连接已关闭');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 运行验证脚本
|
||
|
|
verifyData().then(success => {
|
||
|
|
if (success) {
|
||
|
|
console.log('🎉 数据库表和数据验证成功!');
|
||
|
|
} else {
|
||
|
|
console.log('💥 数据库表和数据验证失败!');
|
||
|
|
}
|
||
|
|
process.exit(success ? 0 : 1);
|
||
|
|
});
|