# -*- coding: utf-8 -*-
from ppms.migration import * 


class ResolveSAPPSPAAEPacket(SucceedOldPacket, SQLPacket):
    """Resolve the CreateTableSapPspAae packet if the table it creates already exists"""
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 21059

    PATH = r'migration.customizing.DB_39_5_10.WI20495_create_table_sap_psp_aae.CreateTableSapPspAae'

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

    def fix(self, runner):
        possible_table_names = ['SAP_PSP_AAE', 'DT975']
        for possible_table_name in possible_table_names:
            if self.table_exists(table_name=possible_table_name):
                self.mark_packet_as_done(self.PATH)
                return self.success()

        return self.fail('No table with name "SAP_PSP_AAE" or "DT975" exist in the database')
