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


class FixViewColumnLength(SQLPacket):
    '''Fix length specification of columns "Pos" and "SAP-State" in view V_DT430_DT472.'''
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14340

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

    def fix(self, runner):
        if self.DBMS == DBMS_ORACLE:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, 'V_DT430_DT472.sql')
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, 'CREATE_DT472.sql', split=True, separator=';/')
        else:
            for sql_file in ['v_dt430_dt472.sql', '01_create_DT472.sql']:
                self.apply_fix_ddl_file(self.sql_planta_de_dbms, sql_file, split=True, separator='GO')
            
        return self.success()