call raiseError('Queries from this file must be runned one by one');

-- -----------------------------------------------------
-- Table tagTL
-- -----------------------------------------------------

alter table tagTL add uofmPre VARCHAR(255) NOT NULL DEFAULT '' after name;
alter table tagTL add uofmPost VARCHAR(255) NOT NULL DEFAULT '' after uofmPre;

insert tagTL(id, languageId, name, uofmPre, uofmPost)
select al.id, al.languageId, tl.name, al.uofmPre, al.uofmPost
from tagTL tl
join attributeTL al on tl.id = al.id and tl.languageId = al.languageId
on duplicate key update
    tagTL.name = tl.name,
    tagTL.uofmPre = al.uofmPre,
    tagTL.uofmPost = al.uofmPost;
    
-- drop table attributeTL;

/* testing queries
select tl.id, tl.name, tl.languageId, ed.externalKey, ed.typeCode, edl.name, tad.koatuu, tad.ukrName, tad.rusName, tad.engName, tad.type, eatl.prefix, eatl.suffix
from tagTL tl
join externalDataT ed on tl.id = ed.tagId
join externalDataTL edl on ed.id = edl.id and tl.languageId = edl.languageId
join tmpAdmterDataT tad on ed.externalKey = tad.koatuu
join externalAdmterTypeTL eatl on tad.type = eatl.id and tl.languageId = eatl.languageId
where ed.externalDataSourceId = 'admter'


select tl.id, tl.name, tl.languageId, ed.externalKey, ed.typeCode, tad.koatuu, tad.ukrName, tad.rusName, tad.engName, tad.type, eatl.prefix, eatl.suffix
from tagTL tl
join externalDataT ed on tl.id = ed.tagId
join tmpAdmterDataT tad on ed.externalKey = tad.koatuu
join externalAdmterTypeTL eatl on tad.type = eatl.id and tl.languageId = eatl.languageId
where ed.externalDataSourceId = 'admter'
*/

/*
update tagTL tl join externalDataT ed on tl.id = ed.tagId join tmpAdmterDataT tad on ed.externalKey = tad.koatuu join externalAdmterTypeTL eatl on tad.type = eatl.id and tl.languageId = eatl.languageId set
	tl.uofmPre = eatl.prefix,
	tl.uofmPost = eatl.suffix
where ed.externalDataSourceId = 'admter';
*/


select __nodeAncestry_UpdateAll(1);
select __object_UpdateAddressesAll(null);
