# -*- coding: utf-8 -*-

from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, VersionType

class ChangeExitToVR(SQLPacket):
    '''Change Exit of DI040537 to a computeSqlValueRange'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 12860

    sql_file = "WI12860_change_exit_to_vr.sql"

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

    def fix(self, runner):
        modify_di = "update dt412 set di001990 = 'PY', di027352 = 'def computeSqlValueRange(dt_name):\n    return ppms.get_query(\"000873\").format(dt_name)', di000252 = '' where di000238 = '040537' and di000252 = '00002380'"


        self.apply_dml_file(self.sql_planta_de_dbms, self.sql_file)

        if not self.modify_and_log(modify_di):
            return self.fail()

        return self.success()
