# -*- coding: utf-8 -*-
import os

from ppms import ppms
from ppms.constants import *
from ppms.migration.packet import *


class ConvertColumns(SQLPacket):
    '''Converts two columns from String to Number.

    These columns (DT390.DI029725 and DT522.DI024338)
    were defined as String (Earth) and are now defined
    as Number (Venus) but still have existing values.
    This packet will convert the old values to the new type.

    Only necessary on an Oracle database.
    '''

    wi_number = 10298
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY

    fname = 'WI10298_EarthToVenus_Convert_columns_from_String_to_Number.sql'

    def fix(self, runner):
        if ppms.db_get_dbms_name() != DBMS_ORACLE:
            self.log('This migration packet is only necessary on a Oracle DB')
            return self.success()

        sqlpath = self.get_sql_file_path(self.sql_planta_de_dbms, self.fname)

        queries = self.get_queries_from_file(sqlpath)
        
        for query in queries:
            self.modify_and_log(query)

        return self.success()