# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.constants import *
from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, MinVersionDependency, VersionType, PacketDependency, \
    PacketState, BasePacket

class AddAMissingColumnInDT470(SQLPacket):

    "Adding a Missing Column in DT470"

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

    STATEMENTS = {DBMS_ORACLE: ("ALTER TABLE DT470 ADD DI063586 NUMBER(10,0)",),
                  DBMS_MSSQL: ("ALTER TABLE DT470 ADD DI063586 NUMERIC(10,0)",)}

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

    def fix(self, runner):
        if ppms.db_get_dbms_name() == DBMS_ORACLE:
            for statement in self.STATEMENTS[DBMS_ORACLE]:
                self.modify_and_log(statement)
            
            return self.success()
            
        if ppms.db_get_dbms_name() == DBMS_MSSQL:
            for statement in self.STATEMENTS[DBMS_MSSQL]:
                self.modify_and_log(statement)
            
            return self.success()