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

from ppms.migration.packet import *


class AddCenterAlignment(SQLPacket, ChangeDTPPacket):
    '''Add the new center alignment value'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10944

    fname = 'wi10944_alignment.sql'

    def fix(self, runner):
        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)

        rec_pos = self.get_record(411, ['021609', 33555], [220])
        rec_numfour = self.get_record(411, ['021609', 57928], [220])

        failures = 0
        if not self.change_value(rec_pos, 'sorting', 0, 1):
            failures += 1

        if not self.change_value(rec_numfour, 'sorting', 1, 0):
            failures += 1

        if failures:
            return self.fail()

        return self.success()
