forked from openlp/openlp
Fix migration for non-sqlite
This commit is contained in:
parent
8780b74342
commit
ddefceee04
@ -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])
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user