diff --git a/etiquette/constants.py b/etiquette/constants.py index c69424b..7092c4b 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -43,11 +43,14 @@ FILENAME_BADCHARS = '\\/:*?<>|"' # happens after the out-of-date check occurs, so no chance of accidentally # overwriting it. DATABASE_VERSION = 14 -DB_INIT = f''' +DB_PRAGMAS = f''' PRAGMA cache_size = 10000; PRAGMA count_changes = OFF; PRAGMA foreign_keys = ON; PRAGMA user_version = {DATABASE_VERSION}; +''' +DB_INIT = f''' +{DB_PRAGMAS} ---------------------------------------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS users( diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 9ee4dbf..1b56cdf 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1314,6 +1314,7 @@ class PhotoDB( if existing_database: if not skip_version_check: self._check_version() + self._load_pragmas() else: self._first_time_setup() @@ -1356,10 +1357,12 @@ class PhotoDB( def _first_time_setup(self): self.log.debug('Running first-time setup.') cur = self.sql.cursor() + cur.executescript(constants.DB_INIT) + self.sql.commit() - statements = constants.DB_INIT.split(';') - for statement in statements: - cur.execute(statement) + def _load_pragmas(self): + cur = self.sql.cursor() + cur.executescript(constants.DB_PRAGMAS) self.sql.commit() def __del__(self):