Journaling for all flights
This commit is contained in:
33
backend/app/models/journal.py
Normal file
33
backend/app/models/journal.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, BigInteger, String, Text, DateTime, Index, func
|
||||
from datetime import datetime
|
||||
from enum import Enum as PyEnum
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class EntityType(str, PyEnum):
|
||||
"""Entity types that can have journal entries"""
|
||||
PPR = "PPR"
|
||||
LOCAL_FLIGHT = "LOCAL_FLIGHT"
|
||||
ARRIVAL = "ARRIVAL"
|
||||
DEPARTURE = "DEPARTURE"
|
||||
|
||||
|
||||
class JournalEntry(Base):
|
||||
"""
|
||||
Generic journal table for tracking changes across all entity types.
|
||||
Replaces the PPR-specific journal table.
|
||||
"""
|
||||
__tablename__ = "journal"
|
||||
|
||||
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
||||
entity_type = Column(String(50), nullable=False, index=True) # PPR, LOCAL_FLIGHT, ARRIVAL, DEPARTURE
|
||||
entity_id = Column(BigInteger, nullable=False, index=True) # ID of the entity
|
||||
entry = Column(Text, nullable=False)
|
||||
user = Column(String(50), nullable=False, index=True)
|
||||
ip = Column(String(45), nullable=True) # Made optional for new entries
|
||||
entry_dt = Column(DateTime, nullable=False, server_default=func.current_timestamp(), index=True)
|
||||
|
||||
# Composite index for efficient queries
|
||||
__table_args__ = (
|
||||
Index('idx_entity_lookup', 'entity_type', 'entity_id'),
|
||||
)
|
||||
@@ -60,17 +60,6 @@ class User(Base):
|
||||
updated_at = Column(DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp())
|
||||
|
||||
|
||||
class Journal(Base):
|
||||
__tablename__ = "journal"
|
||||
|
||||
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
||||
ppr_id = Column(BigInteger, nullable=False, index=True) # Changed to BigInteger to match submitted.id
|
||||
entry = Column(Text, nullable=False)
|
||||
user = Column(String(50), nullable=False, index=True)
|
||||
ip = Column(String(45), nullable=False)
|
||||
entry_dt = Column(DateTime, nullable=False, server_default=func.current_timestamp(), index=True)
|
||||
|
||||
|
||||
class Airport(Base):
|
||||
__tablename__ = "airports"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user