second commit
This commit is contained in:
74
update-user-table.js
Normal file
74
update-user-table.js
Normal file
@@ -0,0 +1,74 @@
|
||||
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 updateUserTable() {
|
||||
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 [columns] = await connection.query('DESCRIBE promptforge_users');
|
||||
const hasPasswordColumn = columns.some(col => col.Field === 'password');
|
||||
|
||||
if (!hasPasswordColumn) {
|
||||
console.log('📝 添加密码字段...');
|
||||
await connection.query(`
|
||||
ALTER TABLE promptforge_users
|
||||
ADD COLUMN password VARCHAR(255) AFTER email
|
||||
`);
|
||||
console.log('✅ 密码字段添加成功');
|
||||
} else {
|
||||
console.log('✅ 密码字段已存在');
|
||||
}
|
||||
|
||||
// 验证表结构
|
||||
console.log('🔍 验证更新后的表结构...');
|
||||
const [updatedColumns] = await connection.query('DESCRIBE promptforge_users');
|
||||
console.log('📋 用户表字段:');
|
||||
updatedColumns.forEach(col => {
|
||||
console.log(` - ${col.Field}: ${col.Type} ${col.Null === 'YES' ? '(可空)' : '(必填)'}`);
|
||||
});
|
||||
|
||||
console.log('🎉 用户表更新完成!');
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 数据库操作失败:', error.message);
|
||||
return false;
|
||||
} finally {
|
||||
if (connection) {
|
||||
await connection.end();
|
||||
console.log('🔌 数据库连接已关闭');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 运行更新脚本
|
||||
updateUserTable().then(success => {
|
||||
if (success) {
|
||||
console.log('🎉 用户表结构更新完成!');
|
||||
} else {
|
||||
console.log('💥 用户表结构更新失败!');
|
||||
}
|
||||
process.exit(success ? 0 : 1);
|
||||
});
|
||||
Reference in New Issue
Block a user