# -*- coding: utf-8 -*-
import os

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


class AddInterfaceFileLoggingField(SQLPacket):
    """Add a new field to the PLANTA Link configuration table for the logging type"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 12059

    sql_script = 'wi12059_add_file_logging.sql'

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

    def fix(self, packet_runner):
        self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_script, split=True)

        self.log('Setting the default value for all existing configurations')
        self.modify_and_log('UPDATE INTERFACE_CONFIG SET LOGTYPE = 496')

        return self.success()
