Skip to content

Commit

Permalink
Merge pull request #1409 from cityofaustin/18533-school-zone-beacons
Browse files Browse the repository at this point in the history
Make school zone beacons from open dataset available to choose in components form
  • Loading branch information
chiaberry authored Sep 26, 2024
2 parents c398c08 + 2744f1b commit 328f2dc
Show file tree
Hide file tree
Showing 28 changed files with 1,410 additions and 67 deletions.
185 changes: 185 additions & 0 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,182 @@
- id
filter: {}
allow_aggregations: true
- table:
name: feature_school_beacons
schema: public
insert_permissions:
- role: moped-admin
permission:
check: {}
set:
created_by_user_id: x-hasura-user-db-id
updated_by_user_id: x-hasura-user-db-id
columns:
- beacon_id
- school_zone_beacon_id
- beacon_name
- component_id
- geography
- is_deleted
- knack_id
- location_name
- zone_name
comment: ""
- role: moped-editor
permission:
check: {}
set:
created_by_user_id: x-hasura-user-db-id
updated_by_user_id: x-hasura-user-db-id
columns:
- beacon_id
- school_zone_beacon_id
- beacon_name
- component_id
- geography
- is_deleted
- knack_id
- location_name
- zone_name
comment: ""
select_permissions:
- role: moped-admin
permission:
columns:
- is_deleted
- component_id
- created_by_user_id
- id
- updated_by_user_id
- beacon_id
- school_zone_beacon_id
- beacon_name
- knack_id
- location_name
- zone_name
- created_at
- updated_at
- geography
filter: {}
comment: ""
- role: moped-editor
permission:
columns:
- is_deleted
- component_id
- created_by_user_id
- id
- updated_by_user_id
- beacon_id
- school_zone_beacon_id
- beacon_name
- knack_id
- location_name
- zone_name
- created_at
- updated_at
- geography
filter: {}
comment: ""
- role: moped-viewer
permission:
columns:
- is_deleted
- component_id
- created_by_user_id
- id
- updated_by_user_id
- beacon_id
- school_zone_beacon_id
- beacon_name
- knack_id
- location_name
- zone_name
- created_at
- updated_at
- geography
filter: {}
comment: ""
update_permissions:
- role: moped-admin
permission:
columns:
- beacon_id
- school_zone_beacon_id
- beacon_name
- component_id
- geography
- is_deleted
- knack_id
- location_name
- zone_name
filter: {}
check: {}
set:
updated_by_user_id: x-hasura-user-db-id
comment: ""
- role: moped-editor
permission:
columns:
- beacon_id
- school_zone_beacon_id
- beacon_name
- component_id
- geography
- is_deleted
- knack_id
- location_name
- zone_name
filter: {}
check: {}
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 Expand Up @@ -2070,6 +2246,15 @@
remote_table:
name: feature_intersections
schema: public
- name: feature_school_beacons
using:
manual_configuration:
column_mapping:
project_component_id: component_id
insertion_order: null
remote_table:
name: feature_school_beacons
schema: public
- name: feature_signals
using:
manual_configuration:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE feature_school_beacons;

DELETE FROM feature_layers WHERE internal_table IN ('feature_school_beacons')
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE public.feature_school_beacons (
school_zone_beacon_id text NOT NULL,
beacon_id text NOT NULL,
knack_id text NOT NULL,
location_name text NOT NULL,
zone_name text NOT NULL,
beacon_name text NOT NULL,
geography geography('MULTIPOINT') NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
created_by_user_id int4 NULL,
updated_by_user_id int4 NULL,
updated_at timestamptz DEFAULT now()
) inherits (features);


ALTER TABLE feature_school_beacons
ADD CONSTRAINT fk_feature_school_beacons_created_by FOREIGN KEY (created_by_user_id) REFERENCES moped_users(user_id),
ADD CONSTRAINT fk_feature_school_beacons_updated_by FOREIGN KEY (updated_by_user_id) REFERENCES moped_users(user_id);

-- Adding comments for audit fields
COMMENT ON COLUMN feature_school_beacons.created_at IS 'Timestamp of when the school beacon feature was created';
COMMENT ON COLUMN feature_school_beacons.created_by_user_id IS 'User ID of the creator of the school beacon feature';
COMMENT ON COLUMN feature_school_beacons.updated_by_user_id IS 'User ID of the last updater of the school beacon feature';
COMMENT ON COLUMN feature_school_beacons.updated_at IS 'Timestamp of the last update of the school beacon feature';

-- Adding comments for feature_school_beacons constraints
COMMENT ON CONSTRAINT fk_feature_school_beacons_created_by ON feature_school_beacons IS 'Foreign key constraint linking created_by_user_id to moped_users table.';
COMMENT ON CONSTRAINT fk_feature_school_beacons_updated_by ON feature_school_beacons IS 'Foreign key constraint linking updated_by_user_id to moped_users table.';

INSERT INTO feature_layers (id, internal_table, reference_layer_primary_key_column) values (6, 'feature_school_beacons', 'school_zone_beacon_id');
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- revert asset layer for school zone beacons
UPDATE moped_components
SET
asset_feature_layer_id = NULL
WHERE
component_subtype = 'School Zone Beacon';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- set asset layer for school beacon to signals
UPDATE moped_components
SET
asset_feature_layer_id = 6
WHERE
component_subtype = 'School Zone Beacon';
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';
Loading

0 comments on commit 328f2dc

Please sign in to comment.