Major refactor WIP

This commit is contained in:
2026-04-03 11:13:44 -04:00
parent dee58e0aae
commit 7b2de645db
25 changed files with 5841 additions and 7760 deletions
+67
View File
@@ -0,0 +1,67 @@
"""Add movements table
Revision ID: 006_movements
Revises: 005_flight_states
Create Date: 2026-04-03 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import Enum
# revision identifiers, used by Alembic.
revision = '006_movements'
down_revision = '005_flight_states'
branch_labels = None
depends_on = None
def upgrade() -> None:
# Create movements table
op.create_table('movements',
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('movement_type', sa.Enum('TAKEOFF', 'LANDING', 'OVERFLIGHT', 'GO_AROUND', 'TOUCH_AND_GO', name='movementtype'), nullable=False),
sa.Column('aircraft_registration', sa.String(length=16), nullable=False),
sa.Column('aircraft_type', sa.String(length=32), nullable=True),
sa.Column('callsign', sa.String(length=16), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=False),
sa.Column('entity_type', sa.String(length=50), nullable=False),
sa.Column('entity_id', sa.BigInteger(), nullable=False),
sa.Column('to_location', sa.String(length=64), nullable=True),
sa.Column('from_location', sa.String(length=64), nullable=True),
sa.Column('runway', sa.String(length=10), nullable=True),
sa.Column('wind', sa.String(length=20), nullable=True),
sa.Column('pressure_setting', sa.String(length=20), nullable=True),
sa.Column('created_by', sa.String(length=16), nullable=True),
sa.Column('ip_address', sa.String(length=45), nullable=True),
sa.Column('notes', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# Create indexes
op.create_index('idx_movement_lookup', 'movements', ['entity_type', 'entity_id'], unique=False)
op.create_index('idx_movement_time', 'movements', ['timestamp', 'movement_type'], unique=False)
op.create_index('ix_movements_movement_type', 'movements', ['movement_type'], unique=False)
op.create_index('ix_movements_aircraft_registration', 'movements', ['aircraft_registration'], unique=False)
op.create_index('ix_movements_timestamp', 'movements', ['timestamp'], unique=False)
op.create_index('ix_movements_entity_type', 'movements', ['entity_type'], unique=False)
op.create_index('ix_movements_created_by', 'movements', ['created_by'], unique=False)
def downgrade() -> None:
# Drop indexes
op.drop_index('ix_movements_created_by', table_name='movements')
op.drop_index('ix_movements_entity_type', table_name='movements')
op.drop_index('ix_movements_timestamp', table_name='movements')
op.drop_index('ix_movements_aircraft_registration', table_name='movements')
op.drop_index('ix_movements_movement_type', table_name='movements')
op.drop_index('idx_movement_time', table_name='movements')
op.drop_index('idx_movement_lookup', table_name='movements')
# Drop table
op.drop_table('movements')
# Drop enum
op.execute("DROP TYPE IF EXISTS movementtype")
@@ -0,0 +1,58 @@
"""Add ACTIVATED status to PPR, PENDING status to departures, arrival_id FK on departures
Revision ID: 007_ppr_activated_status
Revises: 006_movements
Create Date: 2026-04-03 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = '007_ppr_activated_status'
down_revision = '006_movements'
branch_labels = None
depends_on = None
def upgrade() -> None:
# Add ACTIVATED to PPR status enum
op.execute(
"ALTER TABLE submitted MODIFY COLUMN status "
"ENUM('NEW','CONFIRMED','CANCELED','LANDED','DELETED','DEPARTED','ACTIVATED') NOT NULL"
)
# Add PENDING to departures status enum
op.execute(
"ALTER TABLE departures MODIFY COLUMN status "
"ENUM('BOOKED_OUT','GROUND','DEPARTED','LOCAL','CANCELLED','PENDING') NOT NULL"
)
# Add arrival_id FK column to departures (nullable - only set for PPR-activated departures)
op.add_column('departures', sa.Column('arrival_id', sa.BigInteger(), nullable=True))
op.create_foreign_key(
'fk_departures_arrival_id', 'departures', 'arrivals',
['arrival_id'], ['id'], ondelete='SET NULL'
)
op.create_index('idx_departures_arrival_id', 'departures', ['arrival_id'])
def downgrade() -> None:
op.drop_index('idx_departures_arrival_id', table_name='departures')
op.drop_constraint('fk_departures_arrival_id', 'departures', type_='foreignkey')
op.drop_column('departures', 'arrival_id')
op.execute(
"UPDATE departures SET status = 'CANCELLED' WHERE status = 'PENDING'"
)
op.execute(
"ALTER TABLE departures MODIFY COLUMN status "
"ENUM('BOOKED_OUT','GROUND','DEPARTED','LOCAL','CANCELLED') NOT NULL"
)
op.execute(
"UPDATE submitted SET status = 'CONFIRMED' WHERE status = 'ACTIVATED'"
)
op.execute(
"ALTER TABLE submitted MODIFY COLUMN status "
"ENUM('NEW','CONFIRMED','CANCELED','LANDED','DELETED','DEPARTED') NOT NULL"
)