import re
import os

input_file = r'd:\wamp64\www\agents\full_master_dump.sql'
output_file = r'd:\wamp64\www\agents\ready_for_production.sql'

print(f"Iniciando limpieza de DEFINERS en {input_file}...")

# Usamos streaming para no cargar 1GB en memoria
with open(input_file, 'r', encoding='latin1') as fin:
    with open(output_file, 'w', encoding='latin1') as fout:
        for line in fin:
            # Eliminar cláusulas DEFINER
            # Formato común: /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
            # O simplemente DEFINER=`root`@`localhost`
            cleaned_line = re.sub(r'DEFINER=`.*?`@`.*?`', '', line)
            fout.write(cleaned_line)

print(f"Limpieza completada. Archivo listo en: {output_file}")
print(f"Tamaño final: {os.path.getsize(output_file) / (1024*1024):.2f} MB")
