Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audit and council district triggers to feature_school_beacons table #1427

Merged
merged 14 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,51 @@
set:
updated_by_user_id: x-hasura-user-db-id
comment: ""
event_triggers:
- name: activity_log_feature_school_beacons
definition:
enable_manual: false
insert:
columns: '*'
update:
columns: '*'
retry_conf:
interval_sec: 10
num_retries: 0
timeout_sec: 60
webhook_from_env: HASURA_ENDPOINT
headers:
- name: x-hasura-admin-secret
value_from_env: ACTIVITY_LOG_API_SECRET
request_transform:
body:
action: transform
template: |-
{
"query": "mutation InsertActivity($object: moped_activity_log_insert_input!) { insert_moped_activity_log_one(object: $object) { activity_id } }",
"variables": {
"object": {
"record_id": {{ $body.event.data.new.id }},
"record_type": {{ $body.table.name }},
"activity_id": {{ $body.id }},
"record_data": {"event": {{ $body.event }}},
"description": [{"newSchema": "true"}],
"operation_type": {{ $body.event.op }},
"updated_by_user_id": {{ $session_variables?['x-hasura-user-db-id'] ?? 1}}
}
}
}
method: POST
query_params: {}
template_engine: Kriti
version: 2
cleanup_config:
batch_size: 10000
clean_invocation_logs: false
clear_older_than: 168
paused: true
schedule: 0 0 * * *
timeout: 60
- table:
name: feature_signals
schema: public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TRIGGER IF EXISTS update_feature_school_beacons_council_district ON feature_school_beacons;

DROP TRIGGER IF EXISTS feature_school_beacons_parent_audit_log_trigger ON feature_school_beacons;

DROP TRIGGER IF EXISTS set_feature_school_beacons_updated_at ON feature_school_beacons;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE TRIGGER update_feature_school_beacons_council_district BEFORE INSERT OR UPDATE ON
feature_school_beacons FOR EACH ROW EXECUTE FUNCTION update_council_district();
COMMENT ON TRIGGER update_feature_school_beacons_council_district ON feature_school_beacons IS
'Trigger to insert record in feature_council_district table connecting feature_id with corresponding council district id';


-- Trigger for feature_school_beacons table
CREATE TRIGGER feature_school_beacons_parent_audit_log_trigger
AFTER INSERT OR UPDATE ON feature_school_beacons
FOR EACH ROW
EXECUTE FUNCTION update_audit_fields_with_dynamic_parent_table_name("moped_proj_components", "project_component_id", "component_id");
COMMENT ON TRIGGER feature_school_beacons_parent_audit_log_trigger ON feature_school_beacons IS 'Trigger to update parent project and component audit fields';


CREATE TRIGGER set_feature_school_beacons_updated_at
BEFORE INSERT OR UPDATE ON feature_school_beacons
FOR EACH ROW
EXECUTE FUNCTION public.set_updated_at();

COMMENT ON TRIGGER set_feature_school_beacons_updated_at ON public.feature_school_beacons IS 'Trigger to set updated_at timestamp for each insert or update on feature_school_beacons';
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const getFeatureChangesFromComponentForm = (
} else if (newSchoolBeaconKnackId) {
if (
previousSchoolBeacon &&
newSchoolBeaconKnackId !== previousSchoolBeacon.id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! 🙏 this is making me question why we didn't go with Knack id for signals too, but I think that signal_id has shown to be reliable for them.

newSchoolBeaconKnackId !== previousSchoolBeacon.knack_id
) {
// changed which Beacon was chosen
schoolBeaconToCreate =
Expand Down