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

class AddingProbabiltyAndSuccessDimensionDIs_812_872(SQLPacket):

    "Adding Missings Columns in DT812/DT872"

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

    STATEMENTS = {DBMS_ORACLE: ("alter table DT812 add SUCCESS_DIMENSION number(5,0) default 0", 
                                 "alter table DT812 add PROBABILITY number(5,0) default 0",
                                 "alter table DT872 add SUCCESS_DIMENSION number(5,0) default 0", 
                                 "alter table DT872 add PROBABILITY number(5,0) default 0"),
                  DBMS_MSSQL:  ("alter table DT812 add SUCCESS_DIMENSION numeric(5,0) default 0", 
                                 "alter table DT812 add PROBABILITY numeric(5,0) default 0",
                                 "alter table DT872 add SUCCESS_DIMENSION numeric(5,0) default 0", 
                                 "alter table DT872 add PROBABILITY numeric(5,0) default 0")}

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

    def fix(self, runner):
        for statement in self.STATEMENTS[self.DBMS]:
            self.modify_and_log(statement)
        
        return self.success()