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


class RemoveObsoleteSchedulingDFs(SQLPacket):
    """Removes DIs that are no longer touched by scheduling from all modules"""
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 20766

    filename = 'WI20766_remove_obsolete_scheduling_dfs.sql'

    def get_dependencies(self):
        return MaxVersionDependency(version='39.5.11', version_type=VersionType.CUSTOMIZING),

    def delete_old_data(self):
        self.log_heading("Wiping DFs that contain the specified DIs")
        self.apply_dml_file(self.sql_planta_de_ansi, self.filename)

    def fix(self, runner):
        with ppms.autocommit_disabled():
            self.delete_old_data()

        return self.success()
