# Copyright (c) 2020, Xhive Global Ltd. and Contributors
# License: MIT. See LICENSE

import xhiveframework


def execute():
	if not xhiveframework.db.table_exists("Data Import"):
		return

	meta = xhiveframework.get_meta("Data Import")
	# if Data Import is the new one, return early
	if meta.fields[1].fieldname == "import_type":
		return

	xhiveframework.db.sql("DROP TABLE IF EXISTS `tabData Import Legacy`")
	xhiveframework.rename_doc("DocType", "Data Import", "Data Import Legacy")
	xhiveframework.db.commit()
	xhiveframework.db.sql("DROP TABLE IF EXISTS `tabData Import`")
	xhiveframework.rename_doc("DocType", "Data Import Beta", "Data Import")
