import influxframework


def execute():
	influxframework.reload_doc("accounts", "doctype", "bank", force=1)

	if (
		influxframework.db.table_exists("Bank")
		and influxframework.db.table_exists("Bank Account")
		and influxframework.db.has_column("Bank Account", "swift_number")
	):
		try:
			influxframework.db.sql(
				"""
				UPDATE `tabBank` b, `tabBank Account` ba
				SET b.swift_number = ba.swift_number WHERE b.name = ba.bank
			"""
			)
		except Exception as e:
			influxframework.log_error("Bank to Bank Account patch migration failed")

	influxframework.reload_doc("accounts", "doctype", "bank_account")
	influxframework.reload_doc("accounts", "doctype", "payment_request")
