# -*- coding: utf-8 -*-

from ppms import ppms
from ppms.constants import *
from ppms.migration import SQLPacket, PacketCategory, VersionType, MaxVersionDependency


class FixEarnedValueSubprojects(SQLPacket):
    '''Changes V_EVA_PR to also show subprojects correctly'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 16704

    DDL_FILE = 'WI16704_fix_earned_value_subprojects.sql'
    
    def get_dependencies(self):
        return (MaxVersionDependency(version='39.5.7', version_type=VersionType.CUSTOMIZING), )

    def fix(self, runner):
        if self.DBMS == DBMS_ORACLE:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.DDL_FILE)
        elif self.DBMS == DBMS_MSSQL:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.DDL_FILE, split=True, separator='GO$')

        return self.success()