Do a quick content.db check on startup

This commit is contained in:
shortcutme 2018-12-15 18:39:39 +01:00
parent 47316741c1
commit 8e4873cf2a
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 6 additions and 0 deletions

View File

@ -15,10 +15,16 @@ class ContentDb(Db):
try:
self.schema = self.getSchema()
self.checkTables()
self.log.debug("Checking foreign keys...")
foreign_key_error = self.execute("PRAGMA foreign_key_check").fetchone()
if foreign_key_error:
raise Exception("Database foreign key error: %s" % foreign_key_error)
except Exception, err:
self.log.error("Error loading content.db: %s, rebuilding..." % Debug.formatException(err))
self.close()
os.unlink(path) # Remove and try again
Db.__init__(self, {"db_name": "ContentDb", "tables": {}}, path)
self.foreign_keys = True
self.schema = self.getSchema()
self.checkTables()
self.site_ids = {}