# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.migration import *


class PortLoadCurves(SQLPacket):
    """Ports the new 'persistent manual' load curves"""
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_OPTIONAL
    wi_number = 19537

    filename = 'WI19537_port_load_curves.sql'

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

    def delete_old_data(self):
        self.log_heading('Deleting old data')
        self.modify_and_log("delete from dt431 where di000717 in ('PM_QUART', 'PM_YEAR', 'PM_DAY', 'PM_WEEK', 'PM_MONTH')")

    def insert_new_data(self):
        self.log_heading('Inserting new data')
        self.apply_dml_file(self.sql_planta_de_dbms, self.filename)

    def fix(self, runner):
        self.delete_old_data()
        self.insert_new_data()

        return self.success()
