From a34c7b6b7d0aa80b9ee73292a5264e32972ef4a8 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 17 Dec 2022 18:01:32 +0100 Subject: fix migration for old sqlite --- fietsboek/alembic/versions/20221214_c939800af428.py | 19 +++++++++++++++++-- 1 file 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 ### -- cgit v1.2.3