-- P5-6109 de_DE fallback locale to de_AT; delete duplicate text tags

-- Make German german the fallback locale of Austrian german
UPDATE locales
SET fallback_id = (SELECT id from locales where value = 'de_DE')
WHERE value = 'de_AT';


-- Delete de_AT text tags that are identical to the de_DE version
-- (except productTitles category which does not support fallback locales yet)
DELETE FROM "i18n-texts_data"
WHERE
	locale_id = (select id from locales where value = 'de_AT')
	AND textid IN (
		select
			at.textid
		from
			"i18n-texts_data" at
			join "i18n-texts_data" de on at.textid = de.textid and de.locale_id = (select id from locales where value = 'de_DE')
			join "i18n-texts" texts on at.textid = texts.textid
		where
			at.locale_id = (select id from locales where value = 'de_AT')
			and category not in ('productTitles','productDescription')
			and at.text = de.text
		order by at.textid
	)
;
