Database: Check if every episode is assigned to a podcast
This commit is contained in:
parent
b4133bdbcd
commit
2de2456e7f
|
@ -93,6 +93,9 @@ class Database(object):
|
|||
# Check schema version, upgrade if necessary
|
||||
schema.upgrade(self._db, self.database_file)
|
||||
|
||||
# Sanity checks for the data in the database
|
||||
schema.check_data(self)
|
||||
|
||||
logger.debug('Database opened.')
|
||||
return self._db
|
||||
|
||||
|
|
|
@ -25,6 +25,9 @@ from sqlite3 import dbapi2 as sqlite
|
|||
import time
|
||||
import shutil
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
EpisodeColumns = (
|
||||
'podcast_id',
|
||||
'title',
|
||||
|
@ -281,3 +284,10 @@ def convert_gpodder2_db(old_db, new_db):
|
|||
new_db.commit()
|
||||
new_db.close()
|
||||
|
||||
def check_data(db):
|
||||
# All episodes must be assigned to a podcast
|
||||
orphan_episodes = db.get('SELECT COUNT(id) FROM episode '
|
||||
'WHERE podcast_id NOT IN (SELECT id FROM podcast)')
|
||||
if orphan_episodes > 0:
|
||||
logger.error('Orphaned episodes found in database')
|
||||
|
||||
|
|
Loading…
Reference in New Issue