from importlib import __import__ as sima_import
from os.path import isfile
+from os import rename
##
# third parties components
db_file = config.get('sima', 'db_file')
if not isfile(db_file):
logger.debug('Creating database in "%s"', db_file)
- open(db_file, 'a').close() # TODO: to remove with new simadb in v0.18
+ SimaDB(db_path=db_file).create_db()
+ # Migration from v0.17.0
+ dbinfo = SimaDB(db_path=db_file).get_info()
+ if not dbinfo: # v0.17.0 → v0.18+ migration
+ logger.warning('Backing up database!')
+ rename(db_file, db_file + '-old-version-backup')
+ logger.info('Creating an new database in "%s"', db_file)
SimaDB(db_path=db_file).create_db()
if sopt.options.get('command'):
self._db_path, isolation_level=None)
return connection
+ def get_info(self):
+ connection = self.get_database_connection()
+ info = connection.execute("""SELECT * FROM db_info
+ WHERE name = "DB Version" LIMIT 1;""").fetchone()
+ connection.close()
+ return info
+
def create_db(self):
""" Set up a database
"""