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:
@@ -1,9 +1,11 @@
|
||||
"""SQLAlchemy models for chat room management
|
||||
|
||||
Tables:
|
||||
- incident_rooms: Stores room metadata and configuration
|
||||
- room_members: User-room associations with roles
|
||||
- room_templates: Predefined templates for common incident types
|
||||
- tr_incident_rooms: Stores room metadata and configuration
|
||||
- tr_room_members: User-room associations with roles
|
||||
- tr_room_templates: Predefined templates for common incident types
|
||||
|
||||
Note: All tables use 'tr_' prefix to avoid conflicts in shared database.
|
||||
"""
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime, Enum, ForeignKey, UniqueConstraint, Index
|
||||
from sqlalchemy.orm import relationship
|
||||
@@ -46,7 +48,7 @@ class MemberRole(str, enum.Enum):
|
||||
class IncidentRoom(Base):
|
||||
"""Incident room model for production incidents"""
|
||||
|
||||
__tablename__ = "incident_rooms"
|
||||
__tablename__ = "tr_incident_rooms"
|
||||
|
||||
room_id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
title = Column(String(255), nullable=False)
|
||||
@@ -80,18 +82,18 @@ class IncidentRoom(Base):
|
||||
|
||||
# Indexes for common queries
|
||||
__table_args__ = (
|
||||
Index("ix_incident_rooms_status_created", "status", "created_at"),
|
||||
Index("ix_incident_rooms_created_by", "created_by"),
|
||||
Index("ix_tr_incident_rooms_status_created", "status", "created_at"),
|
||||
Index("ix_tr_incident_rooms_created_by", "created_by"),
|
||||
)
|
||||
|
||||
|
||||
class RoomMember(Base):
|
||||
"""Room membership model"""
|
||||
|
||||
__tablename__ = "room_members"
|
||||
__tablename__ = "tr_room_members"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
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)
|
||||
user_id = Column(String(255), nullable=False) # User email/ID
|
||||
role = Column(Enum(MemberRole), nullable=False)
|
||||
|
||||
@@ -106,16 +108,16 @@ class RoomMember(Base):
|
||||
# Constraints and indexes
|
||||
__table_args__ = (
|
||||
# Ensure unique active membership (where removed_at IS NULL)
|
||||
UniqueConstraint("room_id", "user_id", "removed_at", name="uq_room_member_active"),
|
||||
Index("ix_room_members_room_user", "room_id", "user_id"),
|
||||
Index("ix_room_members_user", "user_id"),
|
||||
UniqueConstraint("room_id", "user_id", "removed_at", name="uq_tr_room_member_active"),
|
||||
Index("ix_tr_room_members_room_user", "room_id", "user_id"),
|
||||
Index("ix_tr_room_members_user", "user_id"),
|
||||
)
|
||||
|
||||
|
||||
class RoomTemplate(Base):
|
||||
"""Predefined templates for common incident types"""
|
||||
|
||||
__tablename__ = "room_templates"
|
||||
__tablename__ = "tr_room_templates"
|
||||
|
||||
template_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(100), unique=True, nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user