Catch scenario where names are missing

This commit is contained in:
Ebag333
2017-01-25 09:58:26 -08:00
parent 330983d9dd
commit a366420d65
2 changed files with 39 additions and 3 deletions

View File

@@ -29,9 +29,6 @@ class DatabaseCleanup:
@staticmethod
def OrphanedCharacterSkills(saveddata_engine):
# Finds and fixes database corruption issues.
logger.debug("Start databsae validation and cleanup.")
# Find orphaned character skills.
# This solves an issue where the character doesn't exist, but skills for that character do.
# See issue #917
@@ -102,3 +99,39 @@ class DatabaseCleanup:
logger.error("Database corruption found. Cleaning up %d records.", update.rowcount)
except sqlalchemy.exc.DatabaseError:
logger.error("Failed to connect to database.")
@staticmethod
def NullDamagePatternNames(saveddata_engine):
# Find damage patterns that are missing the name.
# This solves an issue where the damage pattern ends up with a name that is null.
# See issue #949
try:
logger.debug("Running database cleanup for missing damage pattern names.")
# Damage Patterns
results = saveddata_engine.execute("SELECT COUNT(*) AS num FROM damagePatterns WHERE name IS NULL OR name = ''")
row = results.first()
if row and row['num']:
update = saveddata_engine.execute("UPDATE 'damagePatterns' SET 'name' = 'Unknown' WHERE name IS NULL OR name = ''")
logger.error("Database corruption found. Cleaning up %d records.", update.rowcount)
except sqlalchemy.exc.DatabaseError:
logger.error("Failed to connect to database.")
@staticmethod
def NullTargetResistNames(saveddata_engine):
# Find target resists that are missing the name.
# This solves an issue where the target resist ends up with a name that is null.
# See issue #949
try:
logger.debug("Running database cleanup for missing target resist names.")
# Damage Patterns
results = saveddata_engine.execute("SELECT COUNT(*) AS num FROM targetResists WHERE name IS NULL OR name = ''")
row = results.first()
if row and row['num']:
update = saveddata_engine.execute("UPDATE 'targetResists' SET 'name' = 'Unknown' WHERE name IS NULL OR name = ''")
logger.error("Database corruption found. Cleaning up %d records.", update.rowcount)
except sqlalchemy.exc.DatabaseError:
logger.error("Failed to connect to database.")

View File

@@ -61,11 +61,14 @@ if os.path.isfile(config.saveDB):
# Import values that must exist otherwise Pyfa breaks
DefaultDatabaseValues.importRequiredDefaults()
# Finds and fixes database corruption issues.
logging.debug("Starting database validation.")
database_cleanup_instance = DatabaseCleanup()
database_cleanup_instance.OrphanedCharacterSkills(eos.db.saveddata_engine)
database_cleanup_instance.OrphanedFitCharacterIDs(eos.db.saveddata_engine)
database_cleanup_instance.OrphanedFitDamagePatterns(eos.db.saveddata_engine)
database_cleanup_instance.NullDamagePatternNames(eos.db.saveddata_engine)
database_cleanup_instance.NullTargetResistNames(eos.db.saveddata_engine)
logging.debug("Completed database validation.")
else: