# -*- coding: utf-8 -*-
# Copyright (c) 2021, JINGROW
# For license information, please see license.txt


import jingrow


def execute():
	updates = [
		["Site Domain", "Site", "site"],
		["App Release", "App Source", "source"],
		["Deploy Candidate", "Release Group", "group"],
		["Deploy Candidate Difference", "Release Group", "group"],
		["Deploy", "Release Group", "group"],
		["Bench", "Release Group", "group"],
	]
	for target_pagetype, source_pagetype, link_fieldname in updates:
		jingrow.reload_pg("jcloud", "pagetype", jingrow.scrub(target_pagetype))
		jingrow.db.sql(
			f"""
			UPDATE `tab{target_pagetype}` as target
			INNER JOIN `tab{source_pagetype}` as source
			ON `target`.`{link_fieldname}` = `source`.`name`
			SET `target`.team = `source`.team
			WHERE ifnull(`target`.team, '') = ""
		"""
		)
