<?xml version="1.0" encoding="UTF-8"?><database name="egdb3_11_7" schema="action_trigger" type="PostgreSQL - 15.10 (Ubuntu 15.10-1.pgdg24.04+1)">
   <sequences>
      <sequence increment="1" name="alternate_template_id_seq" startValue="1"/>
      <sequence increment="1" name="environment_id_seq" startValue="1"/>
      <sequence increment="1" name="event_def_group_id_seq" startValue="1"/>
      <sequence increment="1" name="event_def_group_member_id_seq" startValue="1"/>
      <sequence increment="1" name="event_definition_id_seq" startValue="1"/>
      <sequence increment="1" name="event_id_seq" startValue="1"/>
      <sequence increment="1" name="event_output_id_seq" startValue="1"/>
      <sequence increment="1" name="event_params_id_seq" startValue="1"/>
   </sequences>
   <tables>
      <table name="alternate_template" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.alternate_template_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="event_def" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="alternate_template_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="template" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="3" name="active" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="locale" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="code" foreignKey="alternate_template_locale_fkey" implied="false" onDeleteCascade="false" schema="config" table="i18n_locale"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="message_title" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="message_template" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <index name="alternate_template_event_def_locale_key" unique="true">
            <column ascending="true" name="event_def"/>
            <column ascending="true" name="locale"/>
         </index>
      </table>
      <table name="cleanup" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="module" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <child column="cleanup_failure" foreignKey="event_definition_cleanup_failure_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
            <child column="cleanup_success" foreignKey="event_definition_cleanup_success_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="description" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="module" sequenceNumberInPK="1"/>
         <index name="cleanup_pkey" unique="true">
            <column ascending="true" name="module"/>
         </index>
      </table>
      <table name="collector" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="module" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <child column="collector" foreignKey="environment_collector_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="environment"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="description" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="module" sequenceNumberInPK="1"/>
         <index name="collector_pkey" unique="true">
            <column ascending="true" name="module"/>
         </index>
      </table>
      <table name="environment" numRows="249" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.environment_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="event_def" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="environment_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="collector" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="module" foreignKey="environment_collector_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="collector"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="label" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="environment_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="env_event_label_once" unique="true">
            <column ascending="true" name="event_def"/>
            <column ascending="true" name="label"/>
         </index>
         <checkConstraint constraint="((label &lt;&gt; ALL (ARRAY['result'::text, 'target'::text, 'event'::text])))" name="environment_label_check"/>
      </table>
      <table name="event" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.event_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="target" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="event_def" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="3" name="add_time" nullable="false" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="4" name="run_time" nullable="false" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="5" name="start_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="6" name="update_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="7" name="complete_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="update_process" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="'pending'::text" digits="0" id="9" name="state" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="10" name="user_data" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="11" name="template_output" nullable="true" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="event_template_output_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_output"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="12" name="error_output" nullable="true" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="event_error_output_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_output"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="13" name="async_output" nullable="true" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="event_async_output_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_output"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="14" name="context_user" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_context_user_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="15" name="context_library" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_context_library_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="16" name="context_bib" nullable="true" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="event_context_bib_fkey" implied="false" onDeleteCascade="false" schema="biblio" table="record_entry"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="17" name="context_item" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="event_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="atev_async_output" unique="false">
            <column ascending="true" name="async_output"/>
         </index>
         <index name="atev_context_item" unique="false">
            <column ascending="true" name="context_item"/>
         </index>
         <index name="atev_context_library" unique="false">
            <column ascending="true" name="context_library"/>
         </index>
         <index name="atev_context_user" unique="false">
            <column ascending="true" name="context_user"/>
         </index>
         <index name="atev_def_state" unique="false">
            <column ascending="true" name="event_def"/>
            <column ascending="true" name="state"/>
         </index>
         <index name="atev_error_output" unique="false">
            <column ascending="true" name="error_output"/>
         </index>
         <index name="atev_target_def_idx" unique="false">
            <column ascending="true" name="target"/>
            <column ascending="true" name="event_def"/>
         </index>
         <index name="atev_template_output" unique="false">
            <column ascending="true" name="template_output"/>
         </index>
         <checkConstraint constraint="((state = ANY (ARRAY['pending'::text, 'invalid'::text, 'found'::text, 'collecting'::text, 'collected'::text, 'validating'::text, 'valid'::text, 'reacting'::text, 'reacted'::text, 'cleaning'::text, 'complete'::text, 'error'::text])))" name="event_state_check"/>
         <checkConstraint constraint="(((user_data IS NULL) OR is_json(user_data)))" name="event_user_data_check"/>
      </table>
      <table name="event_def_group" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.event_def_group_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="grp" foreignKey="event_def_group_member_grp_fkey" implied="false" onDeleteCascade="true" schema="action_trigger" table="event_def_group_member"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="owner" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_def_group_owner_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="hook" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="key" foreignKey="event_def_group_hook_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="hook"/>
         </column>
         <column autoUpdated="false" defaultValue="true" digits="0" id="3" name="active" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="event_def_group_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="event_def_group_member" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.event_def_group_member_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="grp" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_def_group_member_grp_fkey" implied="false" onDeleteCascade="true" schema="action_trigger" table="event_def_group"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="event_def" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_def_group_member_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="true" digits="0" id="3" name="sortable" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="4" name="holdings" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="5" name="external" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="event_def_group_member_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="event_definition" numRows="72" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.event_definition_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="event_def" foreignKey="alternate_template_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="alternate_template"/>
            <child column="event_def" foreignKey="environment_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="environment"/>
            <child column="event_def" foreignKey="event_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event"/>
            <child column="event_def" foreignKey="event_def_group_member_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_def_group_member"/>
            <child column="event_def" foreignKey="event_params_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_params"/>
         </column>
         <column autoUpdated="false" defaultValue="true" digits="0" id="1" name="active" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="owner" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_definition_owner_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="hook" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="key" foreignKey="event_definition_hook_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="hook"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="validator" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="module" foreignKey="event_definition_validator_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="validator"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="reactor" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="module" foreignKey="event_definition_reactor_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="reactor"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="cleanup_success" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="module" foreignKey="event_definition_cleanup_success_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="cleanup"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="cleanup_failure" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="module" foreignKey="event_definition_cleanup_failure_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="cleanup"/>
         </column>
         <column autoUpdated="false" defaultValue="'00:05:00'::interval" digits="6" id="9" name="delay" nullable="false" remarks="" size="49" type="interval" typeCode="1111"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="10" name="max_delay" nullable="true" remarks="" size="49" type="interval" typeCode="1111"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="11" name="repeat_delay" nullable="true" remarks="" size="49" type="interval" typeCode="1111"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="12" name="usr_field" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="13" name="opt_in_setting" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="name" foreignKey="event_definition_opt_in_setting_fkey" implied="false" onDeleteCascade="false" schema="config" table="usr_setting_type"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="14" name="delay_field" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="15" name="group_field" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="16" name="template" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="17" name="granularity" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="18" name="context_usr_path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="19" name="context_library_path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="20" name="context_bib_path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="21" name="context_item_path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="22" name="message_template" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="23" name="message_usr_path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="24" name="message_library_path" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="25" name="message_title" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="26" name="retention_interval" nullable="true" remarks="" size="49" type="interval" typeCode="1111"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="event_definition_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="ev_def_name_owner_once" unique="true">
            <column ascending="true" name="owner"/>
            <column ascending="true" name="name"/>
         </index>
         <index name="ev_def_owner_hook_val_react_clean_delay_once" unique="true">
            <column ascending="true" name="owner"/>
            <column ascending="true" name="hook"/>
            <column ascending="true" name="validator"/>
            <column ascending="true" name="reactor"/>
            <column ascending="true" name="delay"/>
            <column ascending="true" name="delay_field"/>
         </index>
      </table>
      <table name="event_output" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.event_output_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5">
            <child column="async_output" foreignKey="event_async_output_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event"/>
            <child column="error_output" foreignKey="event_error_output_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event"/>
            <child column="template_output" foreignKey="event_template_output_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="1" name="create_time" nullable="false" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="2" name="is_error" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="data" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="locale" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="event_output_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="event_params" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('action_trigger.event_params_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="event_def" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="event_params_event_def_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="param" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="value" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="event_params_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="event_params_event_def_param_once" unique="true">
            <column ascending="true" name="event_def"/>
            <column ascending="true" name="param"/>
         </index>
      </table>
      <table name="hook" numRows="94" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="key" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <child column="hook" foreignKey="event_def_group_hook_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_def_group"/>
            <child column="hook" foreignKey="event_definition_hook_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="core_type" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="description" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="3" name="passive" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="key" sequenceNumberInPK="1"/>
         <index name="hook_pkey" unique="true">
            <column ascending="true" name="key"/>
         </index>
      </table>
      <table name="reactor" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="module" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <child column="reactor" foreignKey="event_definition_reactor_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="description" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="module" sequenceNumberInPK="1"/>
         <index name="reactor_pkey" unique="true">
            <column ascending="true" name="module"/>
         </index>
      </table>
      <table name="validator" remarks="" schema="action_trigger" type="TABLE">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="module" nullable="false" remarks="" size="2147483647" type="text" typeCode="12">
            <child column="validator" foreignKey="event_definition_validator_fkey" implied="false" onDeleteCascade="false" schema="action_trigger" table="event_definition"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="description" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="module" sequenceNumberInPK="1"/>
         <index name="validator_pkey" unique="true">
            <column ascending="true" name="module"/>
         </index>
      </table>
   </tables>
   <routines>
      <routine dataAccess="MODIFIES" deterministic="false" name="check_valid_retention_interval()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    /*
     * 1. Retention intervals are always allowed on active hooks.
     * 2. On passive hooks, retention intervals are only allowed
     *    when the event definition has a max_delay value and the
     *    retention_interval value is greater than the difference 
     *    beteween the delay and max_delay values.
     */ 
    PERFORM TRUE FROM action_trigger.hook 
        WHERE key = NEW.hook AND NOT passive;

    IF FOUND THEN
        RETURN NEW;
    END IF;

    IF NEW.max_delay IS NOT NULL THEN
        IF EXTRACT(EPOCH FROM NEW.retention_interval) > 
            ABS(EXTRACT(EPOCH FROM (NEW.max_delay - NEW.delay))) THEN
            RETURN NEW; -- all good
        ELSE
            RAISE EXCEPTION 'retention_interval is too short';
        END IF;
    ELSE
        RAISE EXCEPTION 'retention_interval requires max_delay';
    END IF;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="purge_events()" returnType="void" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[/**
  * Deleting expired events without simultaneously deleting their outputs
  * creates orphaned outputs.  Deleting their outputs and all of the events 
  * linking back to them, plus any outputs those events link to is messy and 
  * inefficient.  It's simpler to handle them in 2 sweeping steps.
  *
  * 1. Delete expired events.
  * 2. Delete orphaned event outputs.
  *
  * This has the added benefit of removing outputs that may have been
  * orphaned by some other process.  Such outputs are not usuable by
  * the system.
  *
  * This does not guarantee that all events within an event group are
  * purged at the same time.  In such cases, the remaining events will
  * be purged with the next instance of the purge (or soon thereafter).
  * This is another nod toward efficiency over completeness of old 
  * data that's circling the bit bucket anyway.
  */
BEGIN

    DELETE FROM action_trigger.event WHERE id IN (
        SELECT evt.id
        FROM action_trigger.event evt
        JOIN action_trigger.event_definition def ON (def.id = evt.event_def)
        WHERE def.retention_interval IS NOT NULL 
            AND evt.state <> 'pending'
            AND evt.update_time < (NOW() - def.retention_interval)
    );

    WITH linked_outputs AS (
        SELECT templates.id AS id FROM (
            SELECT DISTINCT(template_output) AS id
                FROM action_trigger.event WHERE template_output IS NOT NULL
            UNION
            SELECT DISTINCT(error_output) AS id
                FROM action_trigger.event WHERE error_output IS NOT NULL
            UNION
            SELECT DISTINCT(async_output) AS id
                FROM action_trigger.event WHERE async_output IS NOT NULL
        ) templates
    ) DELETE FROM action_trigger.event_output
        WHERE id NOT IN (SELECT id FROM linked_outputs);

END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
   </routines>
</database>
