# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.migration import SQLPacket, PacketCategory, \
    MinVersionDependency, MaxVersionDependency
from ppms.constants import DBMS_ORACLE
    
class FixPeriodCreation(SQLPacket):
    """Extends the resource column length in table TEMP_PERIOD_CHANGES,
    which is used to create periods, to match the column length in DT467.
    Only needed with Oracle and will do nothing for MSSQL"""

    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 15833

    def get_dependencies(self):
        return(MinVersionDependency(version='39.5.6'),
               MaxVersionDependency(version='39.5.6'))

    def fix(self, packet_runner):
        if ppms.db_get_dbms_name() == DBMS_ORACLE:
            self.modify_and_log("""alter table TEMP_PERIOD_CHANGES 
                                   modify (RES_ID VARCHAR2 (40 CHAR))""")
        
        return self.success()