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

@@ -13,7 +13,7 @@ const router = express.Router();
router.get('/', requireAuth, asyncHandler(async (req, res) => {
const configs = await query(
`SELECT id, provider, api_url, model_name, is_active, created_at, updated_at
FROM llm_configs
FROM 5Why_llm_configs
ORDER BY is_active DESC, created_at DESC`
);
@@ -30,7 +30,7 @@ router.get('/', requireAuth, asyncHandler(async (req, res) => {
router.get('/active', requireAuth, asyncHandler(async (req, res) => {
const [config] = await query(
`SELECT id, provider, api_url, model_name, temperature, max_tokens, timeout
FROM llm_configs
FROM 5Why_llm_configs
WHERE is_active = 1
LIMIT 1`
);
@@ -72,7 +72,7 @@ router.post('/', requireSuperAdmin, asyncHandler(async (req, res) => {
}
const result = await query(
`INSERT INTO llm_configs
`INSERT INTO 5Why_llm_configs
(provider, api_url, api_key, model_name, temperature, max_tokens, timeout)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[
@@ -128,7 +128,7 @@ router.put('/:id', requireSuperAdmin, asyncHandler(async (req, res) => {
}
// 檢查配置是否存在
const [existing] = await query('SELECT id FROM llm_configs WHERE id = ?', [configId]);
const [existing] = await query('SELECT id FROM 5Why_llm_configs WHERE id = ?', [configId]);
if (!existing) {
return res.status(404).json({
success: false,
@@ -137,7 +137,7 @@ router.put('/:id', requireSuperAdmin, asyncHandler(async (req, res) => {
}
await query(
`UPDATE llm_configs
`UPDATE 5Why_llm_configs
SET provider = ?, api_url = ?, api_key = ?, model_name = ?,
temperature = ?, max_tokens = ?, timeout = ?, updated_at = NOW()
WHERE id = ?`,
@@ -178,7 +178,7 @@ router.put('/:id/activate', requireSuperAdmin, asyncHandler(async (req, res) =>
const configId = parseInt(req.params.id);
// 檢查配置是否存在
const [existing] = await query('SELECT id, provider FROM llm_configs WHERE id = ?', [configId]);
const [existing] = await query('SELECT id, provider FROM 5Why_llm_configs WHERE id = ?', [configId]);
if (!existing) {
return res.status(404).json({
success: false,
@@ -187,10 +187,10 @@ router.put('/:id/activate', requireSuperAdmin, asyncHandler(async (req, res) =>
}
// 先停用所有配置
await query('UPDATE llm_configs SET is_active = 0');
await query('UPDATE 5Why_llm_configs SET is_active = 0');
// 啟用指定配置
await query('UPDATE llm_configs SET is_active = 1, updated_at = NOW() WHERE id = ?', [configId]);
await query('UPDATE 5Why_llm_configs SET is_active = 1, updated_at = NOW() WHERE id = ?', [configId]);
// 記錄稽核日誌
await AuditLog.logUpdate(
@@ -217,7 +217,7 @@ router.delete('/:id', requireSuperAdmin, asyncHandler(async (req, res) => {
const configId = parseInt(req.params.id);
// 檢查是否為啟用中的配置
const [existing] = await query('SELECT is_active FROM llm_configs WHERE id = ?', [configId]);
const [existing] = await query('SELECT is_active FROM 5Why_llm_configs WHERE id = ?', [configId]);
if (!existing) {
return res.status(404).json({
success: false,
@@ -232,7 +232,7 @@ router.delete('/:id', requireSuperAdmin, asyncHandler(async (req, res) => {
});
}
await query('DELETE FROM llm_configs WHERE id = ?', [configId]);
await query('DELETE FROM 5Why_llm_configs WHERE id = ?', [configId]);
// 記錄稽核日誌
await AuditLog.logDelete(