Database: Check if every episode is assigned to a podcast

This commit is contained in:
Thomas Perl 2013-03-12 17:15:08 +01:00
parent b4133bdbcd
commit 2de2456e7f
2 changed files with 13 additions and 0 deletions

View File

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

View File

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