migrate old isbn arrays again, fixes #193
This commit is contained in:
parent
a2b55bc24e
commit
e5995a6423
2 changed files with 29 additions and 1 deletions
|
@ -101,4 +101,4 @@ USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
|
|||
|
||||
DEBUG_HTTP = server.get('debug_http', False)
|
||||
|
||||
DB_VERSION = 3
|
||||
DB_VERSION = 4
|
||||
|
|
|
@ -301,6 +301,8 @@ class Update(Thread):
|
|||
db_version = migrate_2()
|
||||
if db_version < 3:
|
||||
db_version = migrate_3()
|
||||
if db_version < 4:
|
||||
db_version = migrate_4()
|
||||
settings.server['db_version'] = settings.DB_VERSION
|
||||
|
||||
def run(self):
|
||||
|
@ -355,3 +357,29 @@ def migrate_3():
|
|||
i.info['pages'] = f.info['pages']
|
||||
i.save()
|
||||
return 3
|
||||
|
||||
def migrate_4():
|
||||
with db.session() as session:
|
||||
import item.models
|
||||
from meta.utils import to_isbn13
|
||||
for i in item.models.Item.query:
|
||||
update = False
|
||||
if 'isbn' in i.meta and isinstance(i.meta['isbn'], list):
|
||||
isbns = [to_isbn13(isbn) for isbn in i.meta['isbn']]
|
||||
isbns = [isbn for isbn in isbns if isbn]
|
||||
if isbns:
|
||||
i.meta['isbn'] = isbns[0]
|
||||
if 'isbn' in i.info:
|
||||
i.info['isbn'] = i.meta['isbn']
|
||||
else:
|
||||
del i.meta['isbn']
|
||||
if 'isbn' in i.info:
|
||||
del i.info['isbn']
|
||||
update = True
|
||||
if 'isbn' in i.meta and not i.meta['isbn']:
|
||||
del i.meta['isbn']
|
||||
update = True
|
||||
if update:
|
||||
session.add(i)
|
||||
session.commit()
|
||||
return 4
|
||||
|
|
Loading…
Reference in a new issue