aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 ###