feat: add database table prefix and complete schema definition

Added `tool_ocr_` prefix to all database tables for clear separation
from other systems in the same database.

Changes:
- All tables now use `tool_ocr_` prefix
- Added tool_ocr_sessions table for token management
- Created complete SQL schema file with:
  - Full table definitions with comments
  - Indexes for performance
  - Views for common queries
  - Stored procedures for maintenance
  - Audit log table (optional)

New files:
- database_schema.sql: Ready-to-use SQL script for deployment

Configuration:
- Added DATABASE_TABLE_PREFIX environment variable
- Updated all references to use prefixed table names

Benefits:
- Clear namespace separation in shared databases
- Easier identification of Tool_OCR tables
- Prevent conflicts with other applications

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-11-14 15:40:24 +08:00
parent 88f9fef2d4
commit 470fa96428
3 changed files with 223 additions and 18 deletions

View File

@@ -5,21 +5,23 @@
- Export current schema and data
- Document any important data to preserve
- [ ] 1.2 Drop old tables
- Remove existing users table
- Remove any related tables
- Remove existing tables with old naming convention
- Clear database for fresh start
- [ ] 1.3 Create new database schema
- Create new `users` table (email as primary identifier)
- Create `ocr_tasks` table with user association
- Create `task_files` table for file tracking
- [ ] 1.3 Create new database schema with `tool_ocr_` prefix
- Create new `tool_ocr_users` table (email as primary identifier)
- Create `tool_ocr_tasks` table with user association
- Create `tool_ocr_task_files` table for file tracking
- Create `tool_ocr_sessions` table for token storage
- Add proper indexes for performance
- [ ] 1.4 Create SQLAlchemy models
- User model (simplified)
- Task model with user relationship
- TaskFile model with cascade delete
- User model (mapped to `tool_ocr_users`)
- Task model (mapped to `tool_ocr_tasks`)
- TaskFile model (mapped to `tool_ocr_task_files`)
- Session model (mapped to `tool_ocr_sessions`)
- Configure table prefix in base model
- [ ] 1.5 Generate Alembic migration
- Create initial migration for new schema
- Test migration script
- Test migration script with proper table prefixes
## 2. Configuration Management
- [ ] 2.1 Update environment configuration
@@ -30,9 +32,11 @@
- Add `TASK_RETENTION_DAYS` for auto-cleanup
- Add `MAX_TASKS_PER_USER` for limits
- Add `ENABLE_TASK_HISTORY` feature flag
- Add `DATABASE_TABLE_PREFIX` = "tool_ocr_"
- [ ] 2.2 Update Settings class
- Add external auth settings to `backend/app/core/config.py`
- Add task management settings
- Add database table prefix configuration
- Add validation for new configuration values
- Remove old authentication settings