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


class ShowBaselineInCostTrends(SQLPacket):
    """Extends the view V_PLANTA_CUMU_DT827 to show baseline data for the
    cost trend charts again"""
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 15049

    sql_file = 'WI15049_show_baseline_in_cost_trends.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_ORACLE:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_file, split=True)
        else:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_file, split=True, separator='GO')

        return self.success()