INIT Commit

This commit is contained in:
Michal Kváček
2023-06-05 09:55:17 +02:00
commit 014a999055
46 changed files with 1645 additions and 0 deletions
@@ -0,0 +1,185 @@
"""first db version
Revision ID: de421195d45c
Revises:
Create Date: 2023-05-06 20:57:49.053470
"""
from alembic import op
import sqlalchemy as sa
import database.custom_types
# 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', database.custom_types.Point(), 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', database.custom_types.Point(), 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', database.custom_types.Point(), 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 ###
@@ -0,0 +1,34 @@
"""password len
Revision ID: 19ce22e5926b
Revises: de421195d45c
Create Date: 2023-05-06 21:01:42.983935
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '19ce22e5926b'
down_revision = 'de421195d45c'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('user', 'password_hashed',
existing_type=mysql.VARCHAR(length=45),
type_=sa.String(length=60),
existing_nullable=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('user', 'password_hashed',
existing_type=sa.String(length=60),
type_=mysql.VARCHAR(length=45),
existing_nullable=False)
# ### end Alembic commands ###
@@ -0,0 +1,28 @@
"""avatar url
Revision ID: 7951a7b79007
Revises: 19ce22e5926b
Create Date: 2023-05-07 21:42:58.261939
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7951a7b79007'
down_revision = '19ce22e5926b'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user', sa.Column('avatar_image_url', sa.String(length=128), nullable=False))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'avatar_image_url')
# ### end Alembic commands ###
@@ -0,0 +1,38 @@
"""edit
Revision ID: d15debffedf8
Revises: 7951a7b79007
Create Date: 2023-05-23 05:42:29.097139
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = 'd15debffedf8'
down_revision = '7951a7b79007'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('aircraft', sa.Column('manufacturer', sa.Text(), server_default='', nullable=False))
op.add_column('aircraft', sa.Column('model', sa.String(length=30), nullable=False))
op.drop_column('aircraft', 'type')
op.alter_column('user', 'avatar_image_url',
existing_type=mysql.VARCHAR(length=128),
nullable=True)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('user', 'avatar_image_url',
existing_type=mysql.VARCHAR(length=128),
nullable=False)
op.add_column('aircraft', sa.Column('type', mysql.VARCHAR(length=30), nullable=False))
op.drop_column('aircraft', 'model')
op.drop_column('aircraft', 'manufacturer')
# ### end Alembic commands ###
@@ -0,0 +1,28 @@
"""edit
Revision ID: 8491bd15ab4a
Revises: d15debffedf8
Create Date: 2023-05-23 05:47:26.866008
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8491bd15ab4a'
down_revision = 'd15debffedf8'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('aircraft', sa.Column('deleted', sa.Boolean(), server_default='0', nullable=False))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('aircraft', 'deleted')
# ### end Alembic commands ###
@@ -0,0 +1,28 @@
"""aircraft photo
Revision ID: 431adcd37681
Revises: 8491bd15ab4a
Create Date: 2023-05-31 20:18:02.644970
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '431adcd37681'
down_revision = '8491bd15ab4a'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('aircraft', sa.Column('photo_filename', sa.String(length=128), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('aircraft', 'photo_filename')
# ### end Alembic commands ###