feat: Migrate to MySQL and add unified environment configuration
## Database Migration (SQLite → MySQL) - Add Alembic migration framework - Add 'tr_' prefix to all tables to avoid conflicts in shared database - Remove SQLite support, use MySQL exclusively - Add pymysql driver dependency - Change ad_token column to Text type for long JWT tokens ## Unified Environment Configuration - Centralize all hardcoded settings to environment variables - Backend: Extend Settings class in app/core/config.py - Frontend: Use Vite environment variables (import.meta.env) - Docker: Move credentials to environment variables - Update .env.example files with comprehensive documentation ## Test Organization - Move root-level test files to tests/ directory: - test_chat_room.py → tests/test_chat_room.py - test_websocket.py → tests/test_websocket.py - test_realtime_implementation.py → tests/test_realtime_implementation.py - Fix path references in test_realtime_implementation.py Breaking Changes: - CORS now requires explicit origins (no more wildcard) - All database tables renamed with 'tr_' prefix - SQLite no longer supported 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,13 +8,13 @@ from app.core.database import Base
|
||||
class RoomFile(Base):
|
||||
"""File uploaded to an incident room"""
|
||||
|
||||
__tablename__ = "room_files"
|
||||
__tablename__ = "tr_room_files"
|
||||
|
||||
# Primary key
|
||||
file_id = Column(String(36), primary_key=True)
|
||||
|
||||
# Foreign key to incident room (CASCADE delete when room is permanently deleted)
|
||||
room_id = Column(String(36), ForeignKey("incident_rooms.room_id", ondelete="CASCADE"), nullable=False)
|
||||
room_id = Column(String(36), ForeignKey("tr_incident_rooms.room_id", ondelete="CASCADE"), nullable=False)
|
||||
|
||||
# File metadata
|
||||
uploader_id = Column(String(255), nullable=False)
|
||||
@@ -36,8 +36,8 @@ class RoomFile(Base):
|
||||
|
||||
# Indexes
|
||||
__table_args__ = (
|
||||
Index("ix_room_files", "room_id", "uploaded_at"),
|
||||
Index("ix_file_uploader", "uploader_id"),
|
||||
Index("ix_tr_room_files_room_uploaded", "room_id", "uploaded_at"),
|
||||
Index("ix_tr_room_files_uploader", "uploader_id"),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -4,7 +4,10 @@ from fastapi import UploadFile, HTTPException
|
||||
from typing import Set
|
||||
import logging
|
||||
|
||||
from app.core.config import get_settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
settings = get_settings()
|
||||
|
||||
# MIME type whitelists
|
||||
IMAGE_TYPES: Set[str] = {
|
||||
@@ -22,11 +25,6 @@ LOG_TYPES: Set[str] = {
|
||||
"text/csv"
|
||||
}
|
||||
|
||||
# File size limits (bytes)
|
||||
IMAGE_MAX_SIZE = 10 * 1024 * 1024 # 10MB
|
||||
DOCUMENT_MAX_SIZE = 20 * 1024 * 1024 # 20MB
|
||||
LOG_MAX_SIZE = 5 * 1024 * 1024 # 5MB
|
||||
|
||||
|
||||
def detect_mime_type(file_data: bytes) -> str:
|
||||
"""
|
||||
@@ -118,11 +116,11 @@ def get_file_type_and_limits(mime_type: str) -> tuple[str, int]:
|
||||
HTTPException if MIME type not recognized
|
||||
"""
|
||||
if mime_type in IMAGE_TYPES:
|
||||
return ("image", IMAGE_MAX_SIZE)
|
||||
return ("image", settings.get_image_max_size_bytes())
|
||||
elif mime_type in DOCUMENT_TYPES:
|
||||
return ("document", DOCUMENT_MAX_SIZE)
|
||||
return ("document", settings.get_document_max_size_bytes())
|
||||
elif mime_type in LOG_TYPES:
|
||||
return ("log", LOG_MAX_SIZE)
|
||||
return ("log", settings.get_log_max_size_bytes())
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
||||
Reference in New Issue
Block a user