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


class AddIndexOnPoolTables(SQLPacket):
    """Add indexes on the pool tables"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14978

    sql_script = 'wi14978_index.sql'

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

    def fix(self, packet_runner):
        self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_script,
                                split=False if ppms.db_get_dbms_name() == DBMS_ORACLE else True)

        return self.success()