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


class ChangeDatatypeOfDi001585(SQLPacket):
    """change datatype of DI001585 to float in DT406 and DT406_HIS"""

    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 21137

    filename = 'WI21137_change_datatype_of_di001585.sql'

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

    def fix(self, packet_runner):

        try:
            self.apply_dml_file(self.sql_planta_de_dbms, self.filename)
            return self.success()
        except ppms.DatabaseError:
            self.log("Error: sql script failed")
            return self.fail()

