Commit 66588675 authored by User expired's avatar User expired
Browse files

update 160915: database changes

parent 65e3c560
-- modifying the schema to assign group to test
ALTER TABLE tce_user_groups ADD COLUMN group_type character varying (5) DEFAULT 'T';
UPDATE tce_user_groups SET group_type = 'B' WHERE external_id LIKE '%owner%';
ALTER TABLE tce_tests ADD COLUMN test_group_id bigint;
-- functions for administrative group
-- Function: get_admin_group(bigint, bigint)
CREATE OR REPLACE FUNCTION get_admin_group(itest_id bigint, igroup_id bigint)
RETURNS bigint AS
$BODY$
DECLARE xgroup_id bigint;
BEGIN
SELECT group_id FROM tce_user_groups
WHERE external_id = (
SELECT LEFT(external_id,strpos(external_id,':')-1)
FROM tce_user_groups
WHERE group_id = igroup_id ) || ':owner'
AND group_type = 'B'
INTO xgroup_id;
IF xgroup_id IS NULL THEN
xgroup_id = igroup_id;
END IF;
RETURN xgroup_id;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
ALTER FUNCTION get_admin_group(bigint, bigint) SET search_path=tcexam, pg_temp;
ALTER FUNCTION get_admin_group(bigint, bigint) OWNER TO tcexam;
-- Function: set_admin_group(bigint, bigint)
CREATE OR REPLACE FUNCTION set_admin_group(itest_id bigint, igroup_id bigint)
RETURNS void AS
$BODY$
BEGIN
IF NOT EXISTS (SELECT * FROM tce_testgroups WHERE tstgrp_group_id = (SELECT * FROM get_admin_group(itest_id, igroup_id)) AND tstgrp_test_id = itest_id)
THEN
INSERT INTO tce_testgroups (
tstgrp_test_id,
tstgrp_group_id
) VALUES ( itest_id, (SELECT * FROM get_admin_group(itest_id, igroup_id)));
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
ALTER FUNCTION set_admin_group(bigint, bigint) SET search_path=tcexam, pg_temp;
ALTER FUNCTION set_admin_group(bigint, bigint) OWNER TO tcexam;
CREATE OR REPLACE FUNCTION insert_tcexam_group(pgroupid character varying, pappointmentid character varying, pgroupname character varying)
RETURNS void AS
$BODY$
DECLARE
externalid character varying;
appointmentid character varying;
groupname character varying;
grouptype character varying;
groupvo xml;
BEGIN
grouptype='T';
externalid = CONCAT (pgroupid,':',pappointmentid);
IF pappointmentid = 'owner' THEN
grouptype = 'B';
pappointmentid = 'Betreuergruppe';
END IF;
groupname = CONCAT (pgroupname ,' - ',pappointmentid);
IF NOT EXISTS(SELECT group_id FROM tce_user_groups WHERE external_id = externalid)
THEN
INSERT INTO tce_user_groups (group_name, external_id,group_type) VALUES (groupname,externalid,grouptype);
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
SECURITY DEFINER
-- Set a secure search_path: trusted schema(s), then 'pg_temp'.
SET search_path = tcexam, pg_temp;
ALTER FUNCTION insert_tcexam_group(character varying, character varying, character varying)
OWNER TO tcexam;
CREATE OR REPLACE FUNCTION update_tcexam_group(pgroupid character varying, pappointmentid character varying, pgroupname character varying)
RETURNS void AS
$BODY$
DECLARE
theKey character varying;
BEGIN
theKey = pgroupid || ':' || pappointmentid;
IF (SELECT group_name FROM tce_user_groups WHERE external_id = theKey) != pgroupname THEN
UPDATE tce_user_groups set group_name = CONCAT(pgroupname, ' - ',pappointmentid) WHERE external_id = theKey;
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
SECURITY DEFINER
-- Set a secure search_path: trusted schema(s), then 'pg_temp'.
SET search_path = tcexam, pg_temp;
ALTER FUNCTION update_tcexam_group(character varying, character varying, character varying)
OWNER TO tcexam;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment