
from ppms.constants import *
from ppms.migration import SQLPacket, PacketCategory


class CreateMSSQLViews(SQLPacket):
    """Adds views required for the recursive sums on the SAP-PSP element tables in MSSQL."""
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 20514

    sql_script = 'wi20514_add_psp_mssql_views.sql'

    def fix(self, runner):
        if self.DBMS != DBMS_MSSQL:
            self.log('This migration packet is only required under MSSQL, so setting it to succeeded!')
            return self.success()

        self.apply_dml_file(self.sql_planta_de_dbms, self.sql_script)
        return self.success()
