from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, MinVersionDependency, VersionType
from ppms.constants import DBMS_MSSQL


class FixEarnedValueOnMSsqlVoE(SQLPacket):
    """
    fixes missing dataitems for earned value analysis in mssql for venus on earth

    SQL-File creates
        * DIs: 061428, 061427, 061426
        * ITexts
        * DFs in DA:
            DI061426 in DA044348
            DI061427 in DA050464
            DI061428 in DA050622
        * SQL-Statement: 000575
    SQL-File modifies module-macro of MOD009ADK

    package will success for oracle
    package will fail if system is not venus on earth
    """

    version = 1
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14443
    run_on_startup = True
    done_after_success = True

    script_name = 'wi14443_fix_earned_value_on_mssql_voe.sql'

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

    def fix(self, runner):
        if self.DBMS != DBMS_MSSQL:
            self.log('Only neccessary in MSSQL.')
            return self.success()

        self.apply_dml_file(self.sql_planta_de_dbms, self.script_name, split=True)
        self.success()