do $$ begin
		if not exists
		(
			select * 
			from INFORMATION_SCHEMA.columns c 
			where c.table_name = 't_branch' and c.COLUMN_NAME = 'curationlevel'
		)
then 
ALTER TABLE AKUZ.T_BRANCH ADD "curationlevel" integer NULL;
end if;
end;$$;

do $$ begin
		if not exists
		(
			select * 
			from INFORMATION_SCHEMA.columns c 
			where c.table_name = 't_branch' and c.COLUMN_NAME = 'datamartpermission'
		)
then 
ALTER TABLE AKUZ.T_BRANCH ADD "datamartpermission" integer null;
UPDATE AKUZ.T_BRANCH SET "datamartpermission" = 3;
ALTER TABLE AKUZ.T_BRANCH ALTER COLUMN "datamartpermission" SET NOT null;
end if;
end;$$;

do $$ begin
		if not exists
		(
			select * 
			from INFORMATION_SCHEMA.columns c 
			where c.table_name = 't_resource' and c.COLUMN_NAME = 'datamartpermission'
		)
then 
ALTER TABLE AKUZ.T_RESOURCE ADD "datamartpermission" integer null;
UPDATE AKUZ.T_RESOURCE SET "datamartpermission" = 3;
ALTER TABLE AKUZ.T_RESOURCE ALTER COLUMN "datamartpermission" SET NOT null;
end if;
end;$$;



