Journaling for all flights
This commit is contained in:
@@ -6,7 +6,8 @@ Create Date: 2025-12-12 12:00:00.000000
|
||||
|
||||
This migration adds a new table for tracking local flights (circuits, local, departure)
|
||||
that don't require PPR submissions. Also adds etd and renames booked_out_dt to created_dt,
|
||||
and departure_dt to departed_dt for consistency.
|
||||
and departure_dt to departed_dt for consistency. Transforms journal table from PPR-specific
|
||||
to a generic polymorphic journal for all entity types.
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@@ -22,8 +23,41 @@ depends_on = None
|
||||
def upgrade() -> None:
|
||||
"""
|
||||
Create local_flights, departures, and arrivals tables.
|
||||
Transform journal table from PPR-specific to generic polymorphic journal.
|
||||
"""
|
||||
|
||||
# Modify existing journal table to support all entity types
|
||||
# First add new columns
|
||||
op.add_column('journal', sa.Column('entity_type', sa.String(50), nullable=True))
|
||||
op.add_column('journal', sa.Column('entity_id', sa.BigInteger(), nullable=True))
|
||||
|
||||
# Migrate existing PPR journal entries: backfill entity_type and entity_id
|
||||
op.execute("""
|
||||
UPDATE journal SET
|
||||
entity_type = 'PPR',
|
||||
entity_id = ppr_id
|
||||
WHERE entity_type IS NULL
|
||||
""")
|
||||
|
||||
# Make new columns NOT NULL after migration
|
||||
op.alter_column('journal', 'entity_type', nullable=False)
|
||||
op.alter_column('journal', 'entity_id', nullable=False)
|
||||
|
||||
# Make ip column nullable (new entries won't always have it)
|
||||
op.alter_column('journal', 'ip', existing_type=sa.String(45), nullable=True)
|
||||
|
||||
# Drop the old ppr_id column
|
||||
op.drop_column('journal', 'ppr_id')
|
||||
|
||||
# Add composite index for efficient queries
|
||||
op.create_index('idx_entity_lookup', 'journal', ['entity_type', 'entity_id'])
|
||||
|
||||
# Drop old index if it exists
|
||||
try:
|
||||
op.drop_index('idx_ppr_id', table_name='journal')
|
||||
except:
|
||||
pass
|
||||
|
||||
op.create_table('local_flights',
|
||||
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
|
||||
sa.Column('registration', sa.String(length=16), nullable=False),
|
||||
|
||||
Reference in New Issue
Block a user