# -*- coding: utf-8 -*-

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


class SetOwnerLicenseForCustomSchema(SQLPacket):
    '''Sets the owner license of customer Schemas to the customer licence

    Sets the owner license of Customer Schemas to the customer licence
    '''
    wi_number = 18564
    done_after_success = False
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY

    def fix(self, runner):
        cust_licence = ppms.db_select("""SELECT DI000001 from dt401 WHERE DI026548 = 1""")[0][0]
        set_schema_licence_querry = """UPDATE DT420 SET Di001911 = {cust_licence} WHERE
            NOT DI000289 = 'K000' AND DI000289 LIKE 'K%'"""
        self.modify_and_log(set_schema_licence_querry.format(cust_licence=cust_licence))
        return self.success()
