# -*- coding: utf-8 -*-

from ppms.migration import SQLPacket, PacketCategory, MinVersionDependency, MaxVersionDependency


class AddLatencyTable(SQLPacket):
    """Add the latency table"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 18809

    sql_script = 'wi18809_latency_table.sql'

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

    def fix(self, packet_runner):
        if not self.column_exists(table_name='LATENCY', column_name='UUID'):
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_script, split=True)

        return self.success()
