aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-12-17 18:01:32 +0100
committerDaniel Schadt <kingdread@gmx.de>2022-12-17 18:03:48 +0100
commita34c7b6b7d0aa80b9ee73292a5264e32972ef4a8 (patch)
tree428daf0adafe642328bb2e96bfbcca7029c5f072
parentb9f170b267d675662fe3b67e90231865d6a33edd (diff)
downloadfietsboek-a34c7b6b7d0aa80b9ee73292a5264e32972ef4a8.tar.gz
fietsboek-a34c7b6b7d0aa80b9ee73292a5264e32972ef4a8.tar.bz2
fietsboek-a34c7b6b7d0aa80b9ee73292a5264e32972ef4a8.zip
fix migration for old sqlite
-rw-r--r--fietsboek/alembic/versions/20221214_c939800af428.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/fietsboek/alembic/versions/20221214_c939800af428.py b/fietsboek/alembic/versions/20221214_c939800af428.py
index eed8bab..79ec899 100644
--- a/fietsboek/alembic/versions/20221214_c939800af428.py
+++ b/fietsboek/alembic/versions/20221214_c939800af428.py
@@ -7,6 +7,7 @@ Create Date: 2022-12-14 23:58:37.983942
"""
from alembic import op
import sqlalchemy as sa
+import logging
# revision identifiers, used by Alembic.
@@ -17,10 +18,24 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
- op.drop_column('tracks', 'gpx')
+ try:
+ op.drop_column('tracks', 'gpx')
+ except sa.exc.OperationalError:
+ # sqlite < 3.35.0 does not know "ALTER TABLE DROP COLUMN", in which
+ # case we probably don't want to break the DB. Instead, we simply
+ # "drop" the column by setting it empty, which should still help in
+ # saving some space.
+ logging.getLogger(__name__).warning(
+ "Your database does not support dropping a column. "
+ "We're setting the content to zero instead."
+ )
+ op.execute("UPDATE tracks SET gpx = '';")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
- op.add_column('tracks', sa.Column('gpx', sa.BLOB(), nullable=True))
+ try:
+ op.add_column('tracks', sa.Column('gpx', sa.BLOB(), nullable=True))
+ except sa.exc.OperationalError:
+ logging.getLogger(__name__).warning("The column already exists.")
# ### end Alembic commands ###