feat: Add 5Why_ prefix to all database tables
- Rename all tables with 5Why_ prefix for namespace isolation - Update models: User.js, Analysis.js, AuditLog.js - Update routes: llmConfig.js - Update scripts: seed-test-users.js, add-deepseek-config.js, add-ollama-config.js - Add migrate-table-prefix.js script for database migration - Update db_schema.sql with new table names - Update views: 5Why_user_analysis_stats, 5Why_recent_analyses Tables renamed: - users -> 5Why_users - analyses -> 5Why_analyses - analysis_perspectives -> 5Why_analysis_perspectives - analysis_whys -> 5Why_analysis_whys - llm_configs -> 5Why_llm_configs - system_settings -> 5Why_system_settings - audit_logs -> 5Why_audit_logs - sessions -> 5Why_sessions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ class User {
|
||||
static async findById(id) {
|
||||
try {
|
||||
const [rows] = await pool.execute(
|
||||
'SELECT id, employee_id, username, email, role, department, position, is_active, created_at, last_login_at FROM users WHERE id = ?',
|
||||
'SELECT id, employee_id, username, email, role, department, position, is_active, created_at, last_login_at FROM 5Why_users WHERE id = ?',
|
||||
[id]
|
||||
);
|
||||
return rows[0] || null;
|
||||
@@ -27,7 +27,7 @@ class User {
|
||||
static async findByEmail(email) {
|
||||
try {
|
||||
const [rows] = await pool.execute(
|
||||
'SELECT * FROM users WHERE email = ? AND is_active = 1',
|
||||
'SELECT * FROM 5Why_users WHERE email = ? AND is_active = 1',
|
||||
[email]
|
||||
);
|
||||
return rows[0] || null;
|
||||
@@ -42,7 +42,7 @@ class User {
|
||||
static async findByEmployeeId(employeeId) {
|
||||
try {
|
||||
const [rows] = await pool.execute(
|
||||
'SELECT * FROM users WHERE employee_id = ? AND is_active = 1',
|
||||
'SELECT * FROM 5Why_users WHERE employee_id = ? AND is_active = 1',
|
||||
[employeeId]
|
||||
);
|
||||
return rows[0] || null;
|
||||
@@ -69,7 +69,7 @@ class User {
|
||||
const passwordHash = await bcrypt.hash(password, 10);
|
||||
|
||||
const [result] = await pool.execute(
|
||||
`INSERT INTO users (employee_id, username, email, password_hash, role, department, position)
|
||||
`INSERT INTO 5Why_users (employee_id, username, email, password_hash, role, department, position)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[employee_id, username, email, passwordHash, role, department, position]
|
||||
);
|
||||
@@ -91,7 +91,7 @@ class User {
|
||||
|
||||
try {
|
||||
await pool.execute(
|
||||
`UPDATE users
|
||||
`UPDATE 5Why_users
|
||||
SET username = ?, email = ?, role = ?, department = ?, position = ?, is_active = ?
|
||||
WHERE id = ?`,
|
||||
[username, email, role, department, position, is_active, id]
|
||||
@@ -110,7 +110,7 @@ class User {
|
||||
try {
|
||||
const passwordHash = await bcrypt.hash(newPassword, 10);
|
||||
await pool.execute(
|
||||
'UPDATE users SET password_hash = ? WHERE id = ?',
|
||||
'UPDATE 5Why_users SET password_hash = ? WHERE id = ?',
|
||||
[passwordHash, id]
|
||||
);
|
||||
return true;
|
||||
@@ -125,7 +125,7 @@ class User {
|
||||
static async updateLastLogin(id) {
|
||||
try {
|
||||
await pool.execute(
|
||||
'UPDATE users SET last_login_at = CURRENT_TIMESTAMP WHERE id = ?',
|
||||
'UPDATE 5Why_users SET last_login_at = CURRENT_TIMESTAMP WHERE id = ?',
|
||||
[id]
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -138,8 +138,8 @@ class User {
|
||||
*/
|
||||
static async getAll(page = 1, limit = 10, filters = {}) {
|
||||
const offset = (page - 1) * limit;
|
||||
let query = 'SELECT id, employee_id, username, email, role, department, position, is_active, created_at FROM users';
|
||||
let countQuery = 'SELECT COUNT(*) as total FROM users';
|
||||
let query = 'SELECT id, employee_id, username, email, role, department, position, is_active, created_at FROM 5Why_users';
|
||||
let countQuery = 'SELECT COUNT(*) as total FROM 5Why_users';
|
||||
const whereParams = [];
|
||||
const whereClauses = [];
|
||||
|
||||
@@ -167,8 +167,9 @@ class User {
|
||||
query += ' ORDER BY created_at DESC LIMIT ? OFFSET ?';
|
||||
|
||||
try {
|
||||
const [rows] = await pool.execute(query, [...whereParams, limit, offset]);
|
||||
const [countResult] = await pool.execute(countQuery, whereParams);
|
||||
// 使用 query 而非 execute,因為 LIMIT 和 OFFSET 參數需要數字類型
|
||||
const [rows] = await pool.query(query, [...whereParams, parseInt(limit), parseInt(offset)]);
|
||||
const [countResult] = await pool.query(countQuery, whereParams);
|
||||
|
||||
return {
|
||||
data: rows,
|
||||
@@ -190,7 +191,7 @@ class User {
|
||||
static async delete(id) {
|
||||
try {
|
||||
await pool.execute(
|
||||
'UPDATE users SET is_active = 0 WHERE id = ?',
|
||||
'UPDATE 5Why_users SET is_active = 0 WHERE id = ?',
|
||||
[id]
|
||||
);
|
||||
return true;
|
||||
@@ -204,7 +205,7 @@ class User {
|
||||
*/
|
||||
static async hardDelete(id) {
|
||||
try {
|
||||
await pool.execute('DELETE FROM users WHERE id = ?', [id]);
|
||||
await pool.execute('DELETE FROM 5Why_users WHERE id = ?', [id]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
throw new Error(`Error hard deleting user: ${error.message}`);
|
||||
@@ -217,7 +218,7 @@ class User {
|
||||
static async getStats(userId) {
|
||||
try {
|
||||
const [rows] = await pool.execute(
|
||||
'SELECT * FROM user_analysis_stats WHERE user_id = ?',
|
||||
'SELECT * FROM 5Why_user_analysis_stats WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
return rows[0] || null;
|
||||
|
||||
Reference in New Issue
Block a user