# -*- coding: utf-8 -*-
from ppms.migration import SQLPacket, PacketCategory, MinVersionDependency, MaxVersionDependency, VersionType


class DeleteUnusedColumns(SQLPacket):
    '''Deactivates and drops columns that are not present in the data dictionary'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 13544

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

    def fix(self, runner):
        statements = ("alter table DT467 drop column DI041591",
                      "alter table DT467 drop column DI042956",
                      "alter table DT472 drop column DI042011",
                      "alter table DT472 drop column DI042012",
                      "alter table DT472 drop column DI042013",
                      "alter table DT472 drop column DI042223",
                      "alter table DT527 drop column DI041348")

        for statement in statements:
            self.modify_and_log(statement)

        return self.success()