- MetricasDiarias now stores both: leads (Google conv) and leads_lake (Airtable count) - Update backfill and migration scripts accordingly - migrate_leads_field.py executed: 49 May records updated Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""
|
|
Migración one-off: renombra el campo 'leads' a 'leads_lake' en MetricasDiarias
|
|
de todos los registros GACampaignMes de mayo 2026.
|
|
"""
|
|
import json
|
|
from airtable_client import AirtableClient
|
|
|
|
at = AirtableClient()
|
|
|
|
print("Cargando registros GACampaignMes de mayo...")
|
|
records = at.gacampaignmes.all(
|
|
formula="AND({Mes}='5',{Año}='2026')",
|
|
fields=["MetricasDiarias"],
|
|
)
|
|
|
|
batch = []
|
|
for r in records:
|
|
raw = r["fields"].get("MetricasDiarias") or "{}"
|
|
try:
|
|
md = json.loads(raw)
|
|
except (json.JSONDecodeError, TypeError):
|
|
md = {}
|
|
|
|
changed = False
|
|
for day_vals in md.values():
|
|
if "leads" in day_vals and "leads_lake" not in day_vals:
|
|
day_vals["leads_lake"] = day_vals.pop("leads")
|
|
changed = True
|
|
|
|
if changed:
|
|
batch.append({
|
|
"id": r["id"],
|
|
"fields": {"MetricasDiarias": json.dumps(md, ensure_ascii=False)},
|
|
})
|
|
|
|
print(f"Registros a migrar: {len(batch)}")
|
|
if not batch:
|
|
print("Nada que migrar.")
|
|
else:
|
|
for i in range(0, len(batch), 10):
|
|
at.gacampaignmes.batch_update(batch[i:i+10])
|
|
print(f" > {min(i+10, len(batch))}/{len(batch)} guardados")
|
|
print(f"OK Migracion completada: {len(batch)} registros actualizados.")
|