Oops, let separate loading of pragmas for not-first-time load.

Since DB_INIT was only run during first time setup, all future
loads were not running the pragmas, not even the FK restriction.
master
voussoir 2018-05-03 19:02:53 -07:00
parent 64449569ea
commit 96d79f2b25
2 changed files with 10 additions and 4 deletions

View File

@ -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(

View File

@ -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):