Skip to content

Commit

Permalink
#91 - fix database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlocker8 committed Apr 22, 2024
1 parent c8ffe39 commit 6dea49b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions sporttracker/migrations/versions/41c4f10f2564_planned_tours.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import sqlalchemy as sa
from alembic import op
from sqlalchemy import Inspector
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
Expand All @@ -18,20 +19,24 @@


def upgrade():
op.create_table(
'planned_tour',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', postgresql.ENUM(name='tracktype', create_type=False), nullable=True),
sa.Column('name', sa.String(), nullable=False),
sa.Column('last_edit_date', sa.DateTime(), nullable=False),
sa.Column('gpxFileName', sa.String(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
['user_id'],
['user.id'],
),
sa.PrimaryKeyConstraint('id'),
)
inspector = Inspector.from_engine(op.get_bind().engine)
tableNames = inspector.get_table_names()

if 'planned_tour' not in tableNames:
op.create_table(
'planned_tour',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', postgresql.ENUM(name='tracktype', create_type=False), nullable=True),
sa.Column('name', sa.String(), nullable=False),
sa.Column('last_edit_date', sa.DateTime(), nullable=False),
sa.Column('gpxFileName', sa.String(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
['user_id'],
['user.id'],
),
sa.PrimaryKeyConstraint('id'),
)


def downgrade():
Expand Down

0 comments on commit 6dea49b

Please sign in to comment.