# Copyright (c) 2020, JINGROW and Contributors
# License: MIT. See LICENSE

import jingrow


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

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

	jingrow.db.sql("DROP TABLE IF EXISTS `tabData Import Legacy`")
	jingrow.rename_pg("PageType", "Data Import", "Data Import Legacy")
	jingrow.db.commit()
	jingrow.db.sql("DROP TABLE IF EXISTS `tabData Import`")
	jingrow.rename_pg("PageType", "Data Import Beta", "Data Import")
