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


class PortMissingTrafficLight(SQLPacket):
    """Ports the missing traffic light dataitem 063727"""
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 20998

    filename = 'wi20998_missing_traffic_light.sql'
    deletion_file = 'wi20998_missing_traffic_light_delete.sql'

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

    def delete_old_data(self):
        self.log_heading('Wiping data that could cause conflicts')
        self.apply_dml_file(self.sql_planta_de_ansi, self.deletion_file)

    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):
        with ppms.autocommit_disabled():
            self.delete_old_data()
            self.insert_new_data()

        return self.success()
