import mysql.connector

conn = mysql.connector.connect(
    host="85.215.144.168",
    port=3306,
    database="pastelerias",
    user="asesoft",
    password="Pantera1"
)
cursor = conn.cursor(dictionary=True)

# Find where the orphaned ingredients point
print("=== ORPHANED INGREDIENTS SAMPLES ===")
cursor.execute("""
    SELECT i.id, i.proceso_id, i.id_materia_prima 
    FROM ob_procesos_ingredientes i
    LEFT JOIN ob_recetas_procesos p ON i.proceso_id = p.id
    WHERE p.id IS NULL
    LIMIT 10;
""")
for row in cursor.fetchall():
    print(row)

# Let's check if the proceso_id in the orphaned list is actually a recipe ID!
# Wait! In the old table structure, ingredients were linked to recipes via receta_id.
# If they migrated using their own migration script or if the import script had receta_id,
# maybe the database was migrated but the ingredients table still has recipe IDs in the proceso_id column?
print("\n=== ARE ORPHANED proceso_id VALUES ACTUALLY receta_id? ===")
cursor.execute("""
    SELECT i.proceso_id, r.codigo, r.descripcion 
    FROM ob_procesos_ingredientes i
    JOIN ob_recetas r ON i.proceso_id = r.id
    LIMIT 10;
""")
for row in cursor.fetchall():
    print(row)

cursor.close()
conn.close()
