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


class ExtendActionIDinDT411HIS(SQLPacket):
    """Extend DI 027481 "Action-ID" in DT411_his so it can contain python method names"""

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

    filename_ddl = 'WI21977_extend_DI027481_action_id_his_ddl.sql'

    def fix(self, packet_runner):
        if self.get_char_length_of_varchar_column(table_name='DT411_HIS', column_name='DI027481') < 40:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.filename_ddl)
        else:
            self.log('Column already is long enough! No change needed')

        return self.success()