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


class PortProfilerItexts(SQLPacket, SucceedOldPacket):
    """Ports missing itexts for profiler DIs"""
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 20379

    PATH = r'migration.hotfix.S_39_5_23.WI20379_port_profiler_itexts.PortProfilerItexts'

    filename = 'WI20379_port_profiler_itexts.sql'
    deletion_file = 'WI20379_port_profiler_itexts_delete.sql'

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

    def delete_old_data(self):
        self.log_heading('Wiping data that could cause conflicts')
        self.apply_dml_file(self.sql_planta_de_ansi, self.deletion_file)

    def insert_new_data(self):
        self.log_heading('Inserting new data')
        self.apply_dml_file(self.sql_planta_de_dbms, self.filename)

    def fix(self, runner):
        with ppms.autocommit_disabled():
            self.delete_old_data()
            self.insert_new_data()

        self.mark_packet_as_done(self.PATH)
        return self.success()
