-- remove existing house numbers

drop temporary table if exists housenums;
create temporary table housenums (
    nodeId int unsigned primary key
) engine=MEMORY;

insert housenums(nodeId)
select t.id
from tagV t
where t.typeId = 17
    and not exists (select 1 from templateT tmpl where tmpl.dstNodeId = t.id);

select attribute_Delete(nodeId)
from housenums;

drop temporary table housenums;

-- add new nodeAncestrySource

start transaction;

insert nodeAncestrySourceT(nodeTypeId, srcNodeTypeId, sorter)
values(2, 17, 30);

commit;


-- set up house numbers

start transaction;

drop temporary table if exists streets;
create temporary table streets(
    nodeId int unsigned primary key
) engine=MEMORY;

insert streets(nodeId)
select t.id
from tagV t
where t.typeCode = 'street';

set @1 = nodeLink_UpdateStart();

select template_CreateSubs(nodeId)
from streets;

set @2 = nodeLink_UpdateEnd();

drop temporary table streets;

commit;

-- refresh node ancestry

select __nodeAncestry_UpdateAll(1);
