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:
donald
2025-12-09 18:19:53 +08:00
parent 66cdcacce9
commit f9ee43b73c
9 changed files with 552 additions and 62 deletions

View File

@@ -24,7 +24,7 @@ class AuditLog {
try {
await pool.execute(
`INSERT INTO audit_logs
`INSERT INTO 5Why_audit_logs
(user_id, action, entity_type, entity_id, old_value, new_value,
ip_address, user_agent, status, error_message)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
@@ -126,10 +126,10 @@ class AuditLog {
const offset = (page - 1) * limit;
let query = `
SELECT al.*, u.username, u.employee_id
FROM audit_logs al
LEFT JOIN users u ON al.user_id = u.id
FROM 5Why_audit_logs al
LEFT JOIN 5Why_users u ON al.user_id = u.id
`;
let countQuery = 'SELECT COUNT(*) as total FROM audit_logs al';
let countQuery = 'SELECT COUNT(*) as total FROM 5Why_audit_logs al';
const params = [];
const whereClauses = [];
@@ -166,11 +166,12 @@ class AuditLog {
}
query += ' ORDER BY al.created_at DESC LIMIT ? OFFSET ?';
params.push(limit, offset);
params.push(parseInt(limit), parseInt(offset));
try {
const [rows] = await pool.execute(query, params);
const [countResult] = await pool.execute(countQuery, params.slice(0, -2));
// 使用 pool.query 而非 pool.execute因為 LIMIT/OFFSET 需要數字類型
const [rows] = await pool.query(query, params);
const [countResult] = await pool.query(countQuery, params.slice(0, -2));
return {
data: rows,
@@ -199,7 +200,7 @@ class AuditLog {
static async cleanup(daysToKeep = 90) {
try {
const [result] = await pool.execute(
'DELETE FROM audit_logs WHERE created_at < DATE_SUB(NOW(), INTERVAL ? DAY)',
'DELETE FROM 5Why_audit_logs WHERE created_at < DATE_SUB(NOW(), INTERVAL ? DAY)',
[daysToKeep]
);
return result.affectedRows;