From d876768771afdff3b5c1fce460c58e4ad7612b59 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 16 Jan 2016 11:17:55 +0530 Subject: [PATCH] empty lists are None not '', fixes #102 --- oml/item/models.py | 2 +- oml/settings.py | 2 +- oml/update.py | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/oml/item/models.py b/oml/item/models.py index 1ea5e61..f92758e 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -181,7 +181,7 @@ class Item(db.Model): value = str(value) value = ox.sort_string(value).lower() elif isinstance(value, list): #empty list - value = '' + value = None if getattr(s, key['id']) != value: setattr(s, key['id'], value) update = True diff --git a/oml/settings.py b/oml/settings.py index a770d8c..4cd5ad3 100644 --- a/oml/settings.py +++ b/oml/settings.py @@ -82,4 +82,4 @@ USER_AGENT = 'OpenMediaLibrary/%s' % VERSION DEBUG_HTTP = server.get('debug_http', False) -DB_VERSION = 0 +DB_VERSION = 1 diff --git a/oml/update.py b/oml/update.py index b770e36..5154220 100644 --- a/oml/update.py +++ b/oml/update.py @@ -18,6 +18,7 @@ import ox from oxtornado import actions import settings +import db import logging @@ -277,7 +278,8 @@ class Update(Thread): db_version = settings.server.get('db_version', 0) if db_version < settings.DB_VERSION: self.status('Migrating database...') - time.sleep(30) + if db_version < 1: + db_version = migrate_1() settings.server['db_version'] = settings.DB_VERSION def run(self): @@ -288,3 +290,12 @@ class Update(Thread): return self.status('Relaunching...', True) restart_oml() + + +def migrate_1(): + with db.session() as session: + import item.models + for s in item.models.Sort.query.filter_by(author=''): + s.item.update_sort() + session.commit() + return 1