From ddefceee04e27484abf4e86233f693e30f3ef91d Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 7 Jan 2016 23:12:03 +0100 Subject: [PATCH] Fix migration for non-sqlite --- openlp/core/utils/db.py | 9 ++++----- openlp/plugins/songs/lib/upgrade.py | 9 +++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/openlp/core/utils/db.py b/openlp/core/utils/db.py index 8fdcbbfb9..3009dad91 100644 --- a/openlp/core/utils/db.py +++ b/openlp/core/utils/db.py @@ -30,9 +30,12 @@ from copy import deepcopy log = logging.getLogger(__name__) +def drop_column(op, tablename, columnname): + drop_columns(op, tablename, [columnname]) + def drop_columns(op, tablename, columns): """ - Column dropping functionality for SQLite, as there is no native support, neither in Alembic, nor in SQLite + Column dropping functionality for SQLite, as there is no DROP COLUMN support in SQLite From https://github.com/klugjohannes/alembic-sqlite """ @@ -65,7 +68,3 @@ def drop_columns(op, tablename, columns): # position op.drop_table(tablename) op.rename_table(new_tablename, tablename) - - -def drop_column(op, tablename, columnname): - drop_columns(op, tablename, [columnname]) diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index a132d341a..09f7ce92a 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -139,7 +139,12 @@ def upgrade_5(session, metadata): # Migrate old data op.execute('INSERT INTO songs_songbooks SELECT song_book_id, id, song_number FROM songs\ - WHERE song_book_id NOT NULL AND song_number NOT NULL') + WHERE song_book_id IS NOT NULL AND song_number IS NOT NULL') # Drop old columns - drop_columns(op, 'songs', ['song_book_id', 'song_number']) + if metadata.bind.url.get_dialect().name == 'sqlite': + drop_columns(op, 'songs', ['song_book_id', 'song_number']) + else: + op.drop_constraint('songs_ibfk_1', 'songs', 'foreignkey') + op.drop_column('songs', 'song_book_id') + op.drop_column('songs', 'song_number')