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

class AddingProbabiltyAndDmgdimensionDIs(SQLPacket):

    "Adding Missings Columns in DT810/DT831"

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

    STATEMENTS = {DBMS_ORACLE: ("alter table DT810 add DMG_DIMENSION number(5,0) default 0", 
                                 "alter table DT810 add PROBABILITY number(5,0) default 0",
                                 "alter table DT831 add DMG_DIMENSION number(5,0) default 0", 
                                 "alter table DT831 add PROBABILITY number(5,0) default 0"),
                  DBMS_MSSQL:  ("alter table DT810 add DMG_DIMENSION numeric(5,0) default 0", 
                                 "alter table DT810 add PROBABILITY numeric(5,0) default 0",
                                 "alter table DT831 add DMG_DIMENSION numeric(5,0) default 0", 
                                 "alter table DT831 add PROBABILITY numeric(5,0) default 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()