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


class FixNullValuesInDBPos(ChangeDTPPacket, SQLPacket):
    '''Sets all (illegal) NULL values in DI Db Pos to 0'''
    wi_number = 14381
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY

    def get_dependencies(self):
        return MaxVersionDependency(version='39.5.7'),

    def fix(self, runner):
        sql = """UPDATE DT412 set DI000241 = 0 WHERE DI000241 IS NULL"""
        self.modify_and_log(sql)

        return self.success()