# -*- coding: latin-1 -*-
from ppms.migration import SQLPacket, PacketCategory, MinVersionDependency,MaxVersionDependency, VersionType

class DeleteInvalidNullLicPackage(SQLPacket):
    '''Deletes the invalid package "NullLicenseFixGenerator" from migration
    history and packages.
    '''
    wi_number = 18152
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY

    def get_dependencies(self):
        return (MaxVersionDependency(version='39.5.7', version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):
        del_history = """delete from MIGRATIONHISTORY
                         where MIGRATIONRULE =
                            (select UUID
                             from MIGRATIONRULE
                             where PYTHONPATH = 'migration.server.S_39_5_13.wi13560_fix_null_license.NullLicenseFixGenerator')"""
        self.modify_and_log(del_history)

        del_mig_rule = """delete from MIGRATIONRULE
                          where PYTHONPATH = 'migration.server.S_39_5_13.wi13560_fix_null_license.NullLicenseFixGenerator'"""
        self.modify_and_log(del_mig_rule)

        return self.success()