<commit_before>CREATE OR REPLACE FUNCTION events.event_type_add(
  prm_token integer, 
  prm_category events.event_category, 
  prm_name text, 
  prm_individual_name boolean)
RETURNS integer
LANGUAGE plpgsql
VOLATILE
AS $$
DECLARE
  ret integer;
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  INSERT INTO events.event_type (ety_category, ety_name, ety_individual_name)
    VALUES (prm_category, prm_name, prm_individual_name)
    RETURNING ety_id INTO ret;
  RETURN ret;
END;
$$;
COMMENT ON FUNCTION events.event_type_add(prm_token integer, prm_category events.event_category, 
  prm_name text, prm_individual_name boolean) IS 'Add a new event type';

CREATE OR REPLACE FUNCTION events.event_type_update(
  prm_token integer, 
  prm_ety_id integer, 
  prm_category events.event_category,
  prm_name text, 
  prm_individual_name boolean)
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  UPDATE events.event_type SET
    ety_category = prm_category,
    ety_name = prm_name,
    ety_individual_name = prm_individual_name
    WHERE ety_id = prm_ety_id;
  IF NOT FOUND THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
END;
$$;
COMMENT ON FUNCTION events.event_type_update(prm_token integer, prm_ety_id integer, 
  prm_category events.event_category, prm_name text, prm_individual_name boolean)
  IS 'Update an event type';

CREATE OR REPLACE FUNCTION events.event_type_delete(prm_token integer, prm_ety_id integer)
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  DELETE FROM events.event_type WHERE ety_id = prm_ety_id;
  IF NOT FOUND THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
END;
$$;
COMMENT ON FUNCTION events.event_type_delete(prm_token integer, prm_ety_id integer) IS 'Delete an event topic (not recursive, links to organizations and topics should be deleted first)';

CREATE OR REPLACE FUNCTION events.event_type_get(prm_token integer, prm_ety_id integer)
RETURNS events.event_type
LANGUAGE plpgsql
STABLE
AS $$
DECLARE
  ret events.event_type;
BEGIN
  PERFORM login._token_assert(prm_token, NULL);
  SELECT * INTO ret FROM events.event_type 
    WHERE ety_id = prm_ety_id;
  IF NOT FOUND THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
  RETURN ret;
END;
$$;
COMMENT ON FUNCTION events.event_type_get(prm_token integer, prm_ety_id integer) IS 'Returns information about an event type';

CREATE OR REPLACE FUNCTION events.event_type_list(prm_token integer, prm_category events.event_category)
RETURNS SETOF events.event_type
LANGUAGE plpgsql
STABLE
AS $$
BEGIN
  RETURN QUERY SELECT * FROM events.event_type
    WHERE (prm_category IS NULL OR prm_category = ety_category) ORDER BY ety_name;
END;
$$;
COMMENT ON FUNCTION events.event_type_list(prm_token integer, prm_category events.event_category) IS 'Returns the list of events types for one or all categories of events ';

CREATE OR REPLACE FUNCTION events.event_type_set_topics(prm_token integer, prm_ety_id integer, prm_top_ids integer[])
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
DECLARE
  t integer;
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  -- Raise an exception if entity does not exist
  IF NOT EXISTS (SELECT 1 FROM events.event_type WHERE ety_id = prm_ety_id) THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
  -- If list is NULL, remove all relations
  IF prm_top_ids ISNULL THEN
    DELETE FROM events.event_type_topic WHERE ety_id = prm_ety_id;<commit_msg>(events) add forgotten asserts<commit_after>CREATE OR REPLACE FUNCTION events.event_type_add(
  prm_token integer, 
  prm_category events.event_category, 
  prm_name text, 
  prm_individual_name boolean)
RETURNS integer
LANGUAGE plpgsql
VOLATILE
AS $$
DECLARE
  ret integer;
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  INSERT INTO events.event_type (ety_category, ety_name, ety_individual_name)
    VALUES (prm_category, prm_name, prm_individual_name)
    RETURNING ety_id INTO ret;
  RETURN ret;
END;
$$;
COMMENT ON FUNCTION events.event_type_add(prm_token integer, prm_category events.event_category, 
  prm_name text, prm_individual_name boolean) IS 'Add a new event type';

CREATE OR REPLACE FUNCTION events.event_type_update(
  prm_token integer, 
  prm_ety_id integer, 
  prm_category events.event_category,
  prm_name text, 
  prm_individual_name boolean)
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  UPDATE events.event_type SET
    ety_category = prm_category,
    ety_name = prm_name,
    ety_individual_name = prm_individual_name
    WHERE ety_id = prm_ety_id;
  IF NOT FOUND THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
END;
$$;
COMMENT ON FUNCTION events.event_type_update(prm_token integer, prm_ety_id integer, 
  prm_category events.event_category, prm_name text, prm_individual_name boolean)
  IS 'Update an event type';

CREATE OR REPLACE FUNCTION events.event_type_delete(prm_token integer, prm_ety_id integer)
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  DELETE FROM events.event_type WHERE ety_id = prm_ety_id;
  IF NOT FOUND THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
END;
$$;
COMMENT ON FUNCTION events.event_type_delete(prm_token integer, prm_ety_id integer) IS 'Delete an event topic (not recursive, links to organizations and topics should be deleted first)';

CREATE OR REPLACE FUNCTION events.event_type_get(prm_token integer, prm_ety_id integer)
RETURNS events.event_type
LANGUAGE plpgsql
STABLE
AS $$
DECLARE
  ret events.event_type;
BEGIN
  PERFORM login._token_assert(prm_token, NULL);
  SELECT * INTO ret FROM events.event_type 
    WHERE ety_id = prm_ety_id;
  IF NOT FOUND THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
  RETURN ret;
END;
$$;
COMMENT ON FUNCTION events.event_type_get(prm_token integer, prm_ety_id integer) IS 'Returns information about an event type';

CREATE OR REPLACE FUNCTION events.event_type_list(prm_token integer, prm_category events.event_category)
RETURNS SETOF events.event_type
LANGUAGE plpgsql
STABLE
AS $$
BEGIN
  PERFORM login._token_assert(prm_token, NULL);
  RETURN QUERY SELECT * FROM events.event_type
    WHERE (prm_category IS NULL OR prm_category = ety_category) ORDER BY ety_name;
END;
$$;
COMMENT ON FUNCTION events.event_type_list(prm_token integer, prm_category events.event_category) IS 'Returns the list of events types for one or all categories of events ';

CREATE OR REPLACE FUNCTION events.event_type_set_topics(prm_token integer, prm_ety_id integer, prm_top_ids integer[])
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
DECLARE
  t integer;
BEGIN
  PERFORM login._token_assert(prm_token, '{organization}');
  -- Raise an exception if entity does not exist
  IF NOT EXISTS (SELECT 1 FROM events.event_type WHERE ety_id = prm_ety_id) THEN
    RAISE EXCEPTION USING ERRCODE = 'no_data_found';
  END IF;
  -- If list is NULL, remove all relations
  IF prm_top_ids ISNULL THEN
    DELETE FROM events.event_type_topic WHERE ety_id = prm_ety_id;
{'fraction_non_alphanumeric': 0.06399447131997235, 'fraction_numerical': 0.00027643400138217003, 'mean_word_length': 5.31413612565445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5144526', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2470, 'n_words': 729}