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.
This commit is contained in:
		
							parent
							
								
									64449569ea
								
							
						
					
					
						commit
						96d79f2b25
					
				
					 2 changed files with 10 additions and 4 deletions
				
			
		|  | @ -43,11 +43,14 @@ FILENAME_BADCHARS = '\\/:*?<>|"' | ||||||
| # happens after the out-of-date check occurs, so no chance of accidentally | # happens after the out-of-date check occurs, so no chance of accidentally | ||||||
| # overwriting it. | # overwriting it. | ||||||
| DATABASE_VERSION = 14 | DATABASE_VERSION = 14 | ||||||
| DB_INIT = f''' | DB_PRAGMAS = f''' | ||||||
| PRAGMA cache_size = 10000; | PRAGMA cache_size = 10000; | ||||||
| PRAGMA count_changes = OFF; | PRAGMA count_changes = OFF; | ||||||
| PRAGMA foreign_keys = ON; | PRAGMA foreign_keys = ON; | ||||||
| PRAGMA user_version = {DATABASE_VERSION}; | PRAGMA user_version = {DATABASE_VERSION}; | ||||||
|  | ''' | ||||||
|  | DB_INIT = f''' | ||||||
|  | {DB_PRAGMAS} | ||||||
| 
 | 
 | ||||||
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ||||||
| CREATE TABLE IF NOT EXISTS users( | CREATE TABLE IF NOT EXISTS users( | ||||||
|  |  | ||||||
|  | @ -1314,6 +1314,7 @@ class PhotoDB( | ||||||
|         if existing_database: |         if existing_database: | ||||||
|             if not skip_version_check: |             if not skip_version_check: | ||||||
|                 self._check_version() |                 self._check_version() | ||||||
|  |             self._load_pragmas() | ||||||
|         else: |         else: | ||||||
|             self._first_time_setup() |             self._first_time_setup() | ||||||
| 
 | 
 | ||||||
|  | @ -1356,10 +1357,12 @@ class PhotoDB( | ||||||
|     def _first_time_setup(self): |     def _first_time_setup(self): | ||||||
|         self.log.debug('Running first-time setup.') |         self.log.debug('Running first-time setup.') | ||||||
|         cur = self.sql.cursor() |         cur = self.sql.cursor() | ||||||
|  |         cur.executescript(constants.DB_INIT) | ||||||
|  |         self.sql.commit() | ||||||
| 
 | 
 | ||||||
|         statements = constants.DB_INIT.split(';') |     def _load_pragmas(self): | ||||||
|         for statement in statements: |         cur = self.sql.cursor() | ||||||
|             cur.execute(statement) |         cur.executescript(constants.DB_PRAGMAS) | ||||||
|         self.sql.commit() |         self.sql.commit() | ||||||
| 
 | 
 | ||||||
|     def __del__(self): |     def __del__(self): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue