diff --git a/frappe/core/doctype/communication_link/patches/copy_communication_date_to_link.py b/frappe/core/doctype/communication_link/patches/copy_communication_date_to_link.py index 0a6cd1ee5e..563acd8f8d 100644 --- a/frappe/core/doctype/communication_link/patches/copy_communication_date_to_link.py +++ b/frappe/core/doctype/communication_link/patches/copy_communication_date_to_link.py @@ -6,18 +6,32 @@ def execute(): batch_size = 10_000 while True: - frappe.db.sql( - """ - update `tabCommunication Link` cl - inner join `tabCommunication` c on cl.parent = c.name - set cl.communication_date = c.communication_date - where cl.communication_date is null - and c.communication_date is not null - limit %s - """, + frappe.db.multisql( + { + "mariadb": """ + update `tabCommunication Link` cl + inner join `tabCommunication` c on cl.parent = c.name + set cl.communication_date = c.communication_date + where cl.communication_date is null + and c.communication_date is not null + limit %s + """, + "postgres": """ + UPDATE "tabCommunication Link" + SET communication_date = sub.communication_date + FROM ( + SELECT cl.name, c.communication_date + FROM "tabCommunication Link" cl + JOIN "tabCommunication" c ON cl.parent = c.name + WHERE cl.communication_date IS NULL + AND c.communication_date IS NOT NULL + LIMIT %s + ) AS sub + WHERE "tabCommunication Link".name = sub.name + """, + }, (batch_size,), ) - frappe.db.commit() if not frappe.db.sql(