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

class CreateViewMapping(SQLPacket):
    ''' Creates the table MAP_DBA_VIEWS, which is used by module "Objektverwendung"
    to access dml of all views in oracle. In mssql this is done directly
    one the system views.'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 6372

    create_map_table = 'WI6372_create_view_mapping.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, runner):
        if ppms.db_get_dbms_name() == DBMS_ORACLE:
            self.apply_dml_file(self.sql_planta_de_dbms, self.create_map_table)

        return self.success()
    
    
