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

# equivalent to wi13952_performance_mssql_venus.py (for MSSQL), which was already released in HF 14
class CreateIndicesForVenusOracle(SQLPacket):
    """Adds neccessary indexes for performance to database.

    This migrationpackage is only needed for Venus (min. DB 39.5) on Venus
    """
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14186

    def get_dependencies(self):
        return (MinVersionDependency(version='39.5', 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):
            sql_file = "wi14186_performance_venus.sql"
            self.apply_rollback_ddl_file(self.sql_planta_de_dbms, sql_file)

        return self.success()
