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

from . import DEFAULT_CUSTOMIZING_DEPENDENCY


class PortConfigHashDI(SQLPacket):
    '''Port the config_hash DI from Venus'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 12020

    DDL = {DBMS_ORACLE: 'alter table INTERFACE_CONFIG add CONFIG_HASH raw(16) default null',
           DBMS_MSSQL: 'alter table INTERFACE_CONFIG add CONFIG_HASH uniqueidentifier default null'}

    fname = 'wi12020_config_hash.sql'

    def get_dependencies(self):
        return DEFAULT_CUSTOMIZING_DEPENDENCY

    def fix(self, runner):
        ppms.db_modify(self.DDL[ppms.db_get_dbms_name()])
        self.apply_dml_file(self.sql_planta_de_dbms, self.fname)

        return self.success()
