import xhiveframework


def execute():
	xhiveframework.reload_doc("hr", "doctype", "training_event")
	xhiveframework.reload_doc("hr", "doctype", "training_event_employee")

	# no need to run the update query as there is no old data
	if not xhiveframework.db.exists(
		"Training Event Employee", {"attendance": ("in", ("Mandatory", "Optional"))}
	):
		return

	xhiveframework.db.sql(
		"""
		UPDATE `tabTraining Event Employee`
		SET is_mandatory = 1
		WHERE attendance = 'Mandatory'
		"""
	)
	xhiveframework.db.sql(
		"""
		UPDATE `tabTraining Event Employee`
		SET attendance = 'Present'
		WHERE attendance in ('Mandatory', 'Optional')
	"""
	)
