# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.migration import SQLPacket, PacketCategory, MinVersionDependency, MaxVersionDependency

class DeleteUnnecessaryMigrationPackets(SQLPacket):
    """ Deletes the migration packets FixDT093ValueRanges and FixTimeBudgetMatrix.

    Deletes the migration packets FixDT093ValueRanges and FixTimeBudgetMatrix
    because they do not change the schema and are not necessary.
    This packet is not available in the release notes.
    """
    wi_number = 16530
    version = 1
    done_after_success = True  
    run_on_startup = True  
    category = PacketCategory.CATEGORY_MANDATORY
    
    def get_dependencies(self):
        return (MinVersionDependency(version='39.5.6'),
                MaxVersionDependency(version='39.5.6'))

    def fix(self, runner):
        statements = ['''
        delete from MIGRATIONHISTORY where MIGRATIONRULE in (
        select UUID from MIGRATIONRULE where PYTHONPATH in (
            'migration.customizing.DB_39_5_5.WI13441_FixTimeBudgetMatrix.FixTimeBudgetMatrix',
            'migration.customizing.DB_39_5_5.WI13419_FixDT093ValueRanges.FixDT093ValueRanges',
            'migration.server.S_39_5_17.WI14269_1_change_audited_to_not_null.ChangeAuditedToNotNull',
            'migration.server.S_39_5_14.WI13719_change_audited_to_not_null.ChangeAuditedToNotNull'))''',
        '''
        delete from MIGRATIONRULE where PYTHONPATH in (
            'migration.customizing.DB_39_5_5.WI13441_FixTimeBudgetMatrix.FixTimeBudgetMatrix',
            'migration.customizing.DB_39_5_5.WI13419_FixDT093ValueRanges.FixDT093ValueRanges',
            'migration.server.S_39_5_17.WI14269_1_change_audited_to_not_null.ChangeAuditedToNotNull',
            'migration.server.S_39_5_14.WI13719_change_audited_to_not_null.ChangeAuditedToNotNull')'''
        ]

        for statement in statements:
            self.modify_and_log(statement)
        return self.success()
