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

class FixBotchedEntityNames(SQLPacket):
    '''Fix botched Entity Names

    The original migration package for WI 12349 contained broken names in the
    version for SQL Server.  This package fixes the damage.
    '''

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

    fname = 'wi14322_fix_botched_entity_names.sql'

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

    def fix(self, runner):
        if (ppms.db_get_dbms_name() == DBMS_MSSQL):
            self.apply_dml_file(self.sql_planta_de_dbms, self.fname)

        return self.success()
