Files
api/alembic/versions/20230506-205749_first_db_version_de421195d45c.py
T

185 lines
8.5 KiB
Python

"""first db version
Revision ID: de421195d45c
Revises:
Create Date: 2023-05-06 20:57:49.053470
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'de421195d45c'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('airport',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('icao_code', sa.String(length=4), nullable=False),
sa.Column('gps_position', sa.Integer(), nullable=True),
sa.Column('elevation', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=128), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('password_hashed', sa.String(length=45), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('copilot',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('license',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('number', sa.String(length=30), nullable=False),
sa.Column('valid_until', sa.DateTime(), nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('metar',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('airport_id', sa.Integer(), nullable=False),
sa.Column('metar', sa.Text(), nullable=False),
sa.Column('issued_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['airport_id'], ['airport.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('organization',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('point_of_interest_type',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('is_public', sa.Boolean(), server_default='0', nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('aircraft',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('type', sa.String(length=30), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('organization_id', sa.Integer(), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('point_of_interest',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('gps_position', sa.Integer(), nullable=True),
sa.Column('type_id', sa.Integer(), nullable=False),
sa.Column('is_public', sa.Boolean(), server_default='0', nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['type_id'], ['point_of_interest_type.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user_is_in_organization',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('organization_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('user_id', 'organization_id')
)
op.create_table('aircraft_notes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('aircraft_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('is_public', sa.Boolean(), server_default='0', nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['aircraft_id'], ['aircraft.id'], ),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('flight',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('takeoff_airport_id', sa.Integer(), nullable=True),
sa.Column('landing_airport_id', sa.Integer(), nullable=True),
sa.Column('aircraft_id', sa.Integer(), nullable=False),
sa.Column('copilot_id', sa.Integer(), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('duration_total', sa.Integer(), nullable=False),
sa.Column('duration_pic', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['aircraft_id'], ['aircraft.id'], ),
sa.ForeignKeyConstraint(['copilot_id'], ['copilot.id'], ),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['landing_airport_id'], ['airport.id'], ),
sa.ForeignKeyConstraint(['takeoff_airport_id'], ['airport.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('flight_track',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('flight_id', sa.Integer(), nullable=False),
sa.Column('poi_id', sa.Integer(), nullable=False),
sa.Column('order', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['flight_id'], ['flight.id'], ),
sa.ForeignKeyConstraint(['poi_id'], ['point_of_interest.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('photo',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('filename', sa.String(length=128), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('gps_position', sa.Integer(), nullable=True),
sa.Column('flight_id', sa.Integer(), nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['flight_id'], ['flight.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('photo')
op.drop_table('flight_track')
op.drop_table('flight')
op.drop_table('aircraft_notes')
op.drop_table('user_is_in_organization')
op.drop_table('point_of_interest')
op.drop_table('aircraft')
op.drop_table('point_of_interest_type')
op.drop_table('organization')
op.drop_table('metar')
op.drop_table('license')
op.drop_table('copilot')
op.drop_table('user')
op.drop_table('airport')
# ### end Alembic commands ###