docs: 更新项目文档,完善需求和技术细节
This commit is contained in:
@@ -131,12 +131,55 @@ class DatabaseInitializer {
|
||||
console.log('✅ 数据库连接验证通过');
|
||||
console.log('─'.repeat(50));
|
||||
|
||||
// 这里可以添加具体的表创建逻辑
|
||||
// 检查并创建uploads表
|
||||
const uploadsTableExists = await this.checkTableExists('uploads');
|
||||
if (!uploadsTableExists) {
|
||||
console.log('📁 创建uploads表...');
|
||||
await this.createUploadsTable();
|
||||
} else {
|
||||
console.log('✅ uploads表已存在');
|
||||
}
|
||||
|
||||
console.log('📋 数据库初始化完成');
|
||||
console.log('✅ 所有检查通过,数据库连接正常');
|
||||
|
||||
await this.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建uploads表
|
||||
*/
|
||||
async createUploadsTable() {
|
||||
const createTableSQL = `
|
||||
CREATE TABLE uploads (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT UNSIGNED NOT NULL,
|
||||
original_name VARCHAR(255) NOT NULL,
|
||||
stored_name VARCHAR(255) NOT NULL,
|
||||
file_path VARCHAR(500) NOT NULL,
|
||||
file_size BIGINT NOT NULL,
|
||||
mime_type VARCHAR(100) NOT NULL,
|
||||
file_type ENUM('image', 'document', 'other') DEFAULT 'image',
|
||||
upload_type VARCHAR(50) NOT NULL COMMENT '上传类型: avatar, product, identification, etc',
|
||||
status ENUM('active', 'deleted') DEFAULT 'active',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_upload_type (upload_type),
|
||||
INDEX idx_created_at (created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件上传记录表'
|
||||
`;
|
||||
|
||||
try {
|
||||
await this.connection.execute(createTableSQL);
|
||||
console.log('✅ uploads表创建成功');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ 创建uploads表失败:', error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行初始化
|
||||
|
||||
Reference in New Issue
Block a user