alter table PARTY_CONTACT add column VISIBLE_TO_PUBLIC tinyint(1) NOT NULL default 0;
alter table PARTY_CONTACT add column VISIBLE_TO_STUDENTS tinyint(1) NOT NULL default 0;
alter table PARTY_CONTACT add column VISIBLE_TO_TEACHERS tinyint(1) NOT NULL default 0;
alter table PARTY_CONTACT add column VISIBLE_TO_EMPLOYEES tinyint(1) NOT NULL default 0;

update PARTY_CONTACT set VISIBLE_TO_STUDENTS = VISIBLE WHERE OJB_CONCRETE_CLASS like "%EmailAddress" and TYPE = "INSTITUTIONAL";
update PARTY_CONTACT set VISIBLE_TO_STUDENTS = VISIBLE WHERE OJB_CONCRETE_CLASS like "%WebAddress" and DEFAULT_CONTACT = 1;
update PARTY_CONTACT set VISIBLE_TO_STUDENTS = VISIBLE WHERE OJB_CONCRETE_CLASS like "%Phone";

update PARTY_CONTACT set VISIBLE_TO_PUBLIC = 1, VISIBLE_TO_STUDENTS = 1, VISIBLE_TO_TEACHERS = 1, VISIBLE_TO_EMPLOYEES = 1 WHERE OJB_CONCRETE_CLASS like "%EmailAddress" AND TYPE = "INSTITUTIONAL";
update PARTY_CONTACT set VISIBLE_TO_PUBLIC = 1, VISIBLE_TO_STUDENTS = 1, VISIBLE_TO_TEACHERS = 1, VISIBLE_TO_EMPLOYEES = 1 WHERE OJB_CONCRETE_CLASS like "%Phone" AND TYPE = "WORK";

select concat('update PARTY_CONTACT set VISIBLE_TO_STUDENTS = 1',
    ' where ID_INTERNAL = ', 
    PC1.ID_INTERNAL, ';') 
as "" from PARTY_CONTACT PC1 
where PC1.OJB_CONCRETE_CLASS 
like "%EmailAddress" 
    and PC1.DEFAULT_CONTACT = 1 
    and PC1.VISIBLE = 1 
    and not exists (select * from PARTY_CONTACT PC2 where PC1.KEY_PARTY = PC2.KEY_PARTY and PC1.OJB_CONCRETE_CLASS = PC2.OJB_CONCRETE_CLASS and PC2.TYPE = "INSTITUTIONAL");

select concat('update PARTY_CONTACT set VISIBLE_TO_TEACHERS = VISIBLE_TO_STUDENTS;') as "";

select concat('update PARTY_CONTACT set VISIBLE_TO_EMPLOYEES = VISIBLE_TO_STUDENTS;') as "";
