67 lines
3.1 KiB
Python
67 lines
3.1 KiB
Python
"""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") |