diff --git a/services/hasura/metadata/databases/default/tables/public_alert.yaml b/services/hasura/metadata/databases/default/tables/public_alert.yaml index 75aea46..692bce4 100644 --- a/services/hasura/metadata/databases/default/tables/public_alert.yaml +++ b/services/hasura/metadata/databases/default/tables/public_alert.yaml @@ -35,8 +35,6 @@ configuration: custom_name: emergencyCallingNotificationSent follow_location: custom_name: followLocation - follow_location_ran: - custom_name: followLocationRan initial_location: custom_name: initialLocation keep_open_at: @@ -84,7 +82,6 @@ configuration: device_id: deviceId emergency_calling_notification_sent: emergencyCallingNotificationSent follow_location: followLocation - follow_location_ran: followLocationRan initial_location: initialLocation keep_open_at: keepOpenAt last_address: lastAddress @@ -147,7 +144,6 @@ select_permissions: - code - created_at - follow_location - - follow_location_ran - heading - id - initial_location @@ -191,7 +187,6 @@ select_permissions: - code - created_at - follow_location - - follow_location_ran - heading - id - initial_location diff --git a/services/hasura/migrations/default/1748767404163_alter_table_public_archived_alert_add_column_initial_location/down.sql b/services/hasura/migrations/default/1748767404163_alter_table_public_archived_alert_add_column_initial_location/down.sql new file mode 100644 index 0000000..14b4122 --- /dev/null +++ b/services/hasura/migrations/default/1748767404163_alter_table_public_archived_alert_add_column_initial_location/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."archived_alert" add column "initial_location" geography +-- null; diff --git a/services/hasura/migrations/default/1748767404163_alter_table_public_archived_alert_add_column_initial_location/up.sql b/services/hasura/migrations/default/1748767404163_alter_table_public_archived_alert_add_column_initial_location/up.sql new file mode 100644 index 0000000..9591969 --- /dev/null +++ b/services/hasura/migrations/default/1748767404163_alter_table_public_archived_alert_add_column_initial_location/up.sql @@ -0,0 +1,2 @@ +alter table "public"."archived_alert" add column "initial_location" geography + null; diff --git a/services/hasura/migrations/default/1748767416599_alter_table_public_archived_alert_add_column_follow_location/down.sql b/services/hasura/migrations/default/1748767416599_alter_table_public_archived_alert_add_column_follow_location/down.sql new file mode 100644 index 0000000..3055ac4 --- /dev/null +++ b/services/hasura/migrations/default/1748767416599_alter_table_public_archived_alert_add_column_follow_location/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."archived_alert" add column "follow_location" boolean +-- null default 'false'; diff --git a/services/hasura/migrations/default/1748767416599_alter_table_public_archived_alert_add_column_follow_location/up.sql b/services/hasura/migrations/default/1748767416599_alter_table_public_archived_alert_add_column_follow_location/up.sql new file mode 100644 index 0000000..b8d53fa --- /dev/null +++ b/services/hasura/migrations/default/1748767416599_alter_table_public_archived_alert_add_column_follow_location/up.sql @@ -0,0 +1,2 @@ +alter table "public"."archived_alert" add column "follow_location" boolean + null default 'false'; diff --git a/services/hasura/migrations/default/1748767476240_alter_table_public_archived_alert_add_column_last_address/down.sql b/services/hasura/migrations/default/1748767476240_alter_table_public_archived_alert_add_column_last_address/down.sql new file mode 100644 index 0000000..44202a6 --- /dev/null +++ b/services/hasura/migrations/default/1748767476240_alter_table_public_archived_alert_add_column_last_address/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."archived_alert" add column "last_address" text +-- null; diff --git a/services/hasura/migrations/default/1748767476240_alter_table_public_archived_alert_add_column_last_address/up.sql b/services/hasura/migrations/default/1748767476240_alter_table_public_archived_alert_add_column_last_address/up.sql new file mode 100644 index 0000000..c940f2d --- /dev/null +++ b/services/hasura/migrations/default/1748767476240_alter_table_public_archived_alert_add_column_last_address/up.sql @@ -0,0 +1,2 @@ +alter table "public"."archived_alert" add column "last_address" text + null; diff --git a/services/hasura/migrations/default/1748767491124_alter_table_public_archived_alert_add_column_last_what3words/down.sql b/services/hasura/migrations/default/1748767491124_alter_table_public_archived_alert_add_column_last_what3words/down.sql new file mode 100644 index 0000000..e91c9e2 --- /dev/null +++ b/services/hasura/migrations/default/1748767491124_alter_table_public_archived_alert_add_column_last_what3words/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."archived_alert" add column "last_what3words" text +-- null; diff --git a/services/hasura/migrations/default/1748767491124_alter_table_public_archived_alert_add_column_last_what3words/up.sql b/services/hasura/migrations/default/1748767491124_alter_table_public_archived_alert_add_column_last_what3words/up.sql new file mode 100644 index 0000000..354dab2 --- /dev/null +++ b/services/hasura/migrations/default/1748767491124_alter_table_public_archived_alert_add_column_last_what3words/up.sql @@ -0,0 +1,2 @@ +alter table "public"."archived_alert" add column "last_what3words" text + null; diff --git a/services/hasura/migrations/default/1748767501611_alter_table_public_archived_alert_add_column_last_nearest_place/down.sql b/services/hasura/migrations/default/1748767501611_alter_table_public_archived_alert_add_column_last_nearest_place/down.sql new file mode 100644 index 0000000..840ed85 --- /dev/null +++ b/services/hasura/migrations/default/1748767501611_alter_table_public_archived_alert_add_column_last_nearest_place/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."archived_alert" add column "last_nearest_place" text +-- null; diff --git a/services/hasura/migrations/default/1748767501611_alter_table_public_archived_alert_add_column_last_nearest_place/up.sql b/services/hasura/migrations/default/1748767501611_alter_table_public_archived_alert_add_column_last_nearest_place/up.sql new file mode 100644 index 0000000..6960d5f --- /dev/null +++ b/services/hasura/migrations/default/1748767501611_alter_table_public_archived_alert_add_column_last_nearest_place/up.sql @@ -0,0 +1,2 @@ +alter table "public"."archived_alert" add column "last_nearest_place" text + null; diff --git a/services/hasura/migrations/default/1748767836011_alter_table_public_alert_drop_column_follow_location_ran/down.sql b/services/hasura/migrations/default/1748767836011_alter_table_public_alert_drop_column_follow_location_ran/down.sql new file mode 100644 index 0000000..9d3a196 --- /dev/null +++ b/services/hasura/migrations/default/1748767836011_alter_table_public_alert_drop_column_follow_location_ran/down.sql @@ -0,0 +1,3 @@ +alter table "public"."alert" alter column "follow_location_ran" set default false; +alter table "public"."alert" alter column "follow_location_ran" drop not null; +alter table "public"."alert" add column "follow_location_ran" bool; diff --git a/services/hasura/migrations/default/1748767836011_alter_table_public_alert_drop_column_follow_location_ran/up.sql b/services/hasura/migrations/default/1748767836011_alter_table_public_alert_drop_column_follow_location_ran/up.sql new file mode 100644 index 0000000..e4da5f8 --- /dev/null +++ b/services/hasura/migrations/default/1748767836011_alter_table_public_alert_drop_column_follow_location_ran/up.sql @@ -0,0 +1 @@ +alter table "public"."alert" drop column "follow_location_ran" cascade; diff --git a/services/hasura/migrations/default/1748767936428_archive-alert_update/down.sql b/services/hasura/migrations/default/1748767936428_archive-alert_update/down.sql new file mode 100644 index 0000000..1eccd2f --- /dev/null +++ b/services/hasura/migrations/default/1748767936428_archive-alert_update/down.sql @@ -0,0 +1,174 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- CREATE OR REPLACE FUNCTION public.archive_alert(p_id integer) +-- RETURNS void +-- LANGUAGE plpgsql +-- AS $function$ +-- DECLARE +-- v_archived_alert_id INTEGER; +-- BEGIN +-- -- Insert the selected alert into the archived_alert table +-- INSERT INTO archived_alert ( +-- "alert_id", +-- "user_id", +-- "phone_number_id", +-- "device_id", +-- "location", +-- "alert_tag", +-- "created_at", +-- "call_emergency", +-- "notify_around", +-- "notify_relatives", +-- "level", +-- "subject", +-- "accuracy", +-- "altitude", +-- "altitude_accuracy", +-- "heading", +-- "speed", +-- "radius", +-- "address", +-- "what3words", +-- "nearest_place", +-- "uuid", +-- "code", +-- "notified_count", +-- "closed_at", +-- "keep_open_at", +-- "updated_at", +-- "suggest_close_sent", +-- "suggest_keep_open_sent", +-- "closed_by", +-- "emergency_calling_notification_sent", +-- "acknowledged_relative_count", +-- "acknowledged_around_count", +-- "acknowledged_connect_count", +-- "alerting_relative_count", +-- "alerting_around_count", +-- "alerting_connect_count", +-- "initial_location", +-- "follow_location", +-- "last_address", +-- "last_what3words", +-- "last_nearest_place" +-- ) +-- SELECT +-- "id", +-- "user_id", +-- "phone_number_id", +-- "device_id", +-- "location", +-- "alert_tag", +-- "created_at", +-- "call_emergency", +-- "notify_around", +-- "notify_relatives", +-- "level", +-- "subject", +-- "accuracy", +-- "altitude", +-- "altitude_accuracy", +-- "heading", +-- "speed", +-- "radius", +-- "address", +-- "what3words", +-- "nearest_place", +-- "uuid", +-- "code", +-- "notified_count", +-- "closed_at", +-- "keep_open_at", +-- "updated_at", +-- "suggest_close_sent", +-- "suggest_keep_open_sent", +-- "closed_by", +-- "emergency_calling_notification_sent", +-- "acknowledged_relative_count", +-- "acknowledged_around_count", +-- "acknowledged_connect_count", +-- "alerting_relative_count", +-- "alerting_around_count", +-- "alerting_connect_count", +-- "initial_location", +-- "follow_location", +-- "last_address", +-- "last_what3words", +-- "last_nearest_place" +-- FROM "alert" +-- WHERE "id" = p_id +-- RETURNING "id" INTO v_archived_alert_id; +-- +-- -- Insert related alerted records into the archived_alerted table +-- INSERT INTO +-- "alerted" ( +-- "archived_alert_id", +-- "user_id", +-- "opened_once", +-- "created_at", +-- "near_location", +-- "opened", +-- "device_id", +-- "initial_location", +-- "notification_sent", +-- "notification_sent_at", +-- "initial_distance", +-- "geomatch_method", +-- "reason", +-- "updated_at", +-- "coming_help", +-- "relative_user_id" +-- ) +-- SELECT +-- v_archived_alert_id, +-- "user_id", +-- "opened_once", +-- "created_at", +-- "near_location", +-- "opened", +-- "device_id", +-- "initial_location", +-- "notification_sent", +-- "notification_sent_at", +-- "initial_distance", +-- "geomatch_method", +-- "reason", +-- "updated_at", +-- "coming_help", +-- "relative_user_id" +-- FROM "alerting" +-- WHERE "alert_id" = p_id; +-- +-- -- Insert related messages into the archived_message table +-- INSERT INTO archived_message ( +-- "archived_alert_id", +-- "user_id", +-- "device_id", +-- "content_type", +-- "text", +-- "audio_file_uuid", +-- "location", +-- "created_at" +-- ) +-- SELECT +-- v_archived_alert_id, +-- "user_id", +-- "device_id", +-- "content_type", +-- "text", +-- "audio_file_uuid", +-- "location", +-- "created_at" +-- FROM "message" +-- WHERE "alert_id" = p_id; +-- +-- -- Delete the messages from the message table +-- DELETE FROM "message" +-- WHERE "alert_id" = p_id; +-- +-- -- Delete the alert from the alert table +-- DELETE FROM "alert" +-- WHERE id = p_id; +-- +-- END; +-- $function$; diff --git a/services/hasura/migrations/default/1748767936428_archive-alert_update/up.sql b/services/hasura/migrations/default/1748767936428_archive-alert_update/up.sql new file mode 100644 index 0000000..62aaaf6 --- /dev/null +++ b/services/hasura/migrations/default/1748767936428_archive-alert_update/up.sql @@ -0,0 +1,172 @@ +CREATE OR REPLACE FUNCTION public.archive_alert(p_id integer) + RETURNS void + LANGUAGE plpgsql +AS $function$ +DECLARE + v_archived_alert_id INTEGER; +BEGIN + -- Insert the selected alert into the archived_alert table + INSERT INTO archived_alert ( + "alert_id", + "user_id", + "phone_number_id", + "device_id", + "location", + "alert_tag", + "created_at", + "call_emergency", + "notify_around", + "notify_relatives", + "level", + "subject", + "accuracy", + "altitude", + "altitude_accuracy", + "heading", + "speed", + "radius", + "address", + "what3words", + "nearest_place", + "uuid", + "code", + "notified_count", + "closed_at", + "keep_open_at", + "updated_at", + "suggest_close_sent", + "suggest_keep_open_sent", + "closed_by", + "emergency_calling_notification_sent", + "acknowledged_relative_count", + "acknowledged_around_count", + "acknowledged_connect_count", + "alerting_relative_count", + "alerting_around_count", + "alerting_connect_count", + "initial_location", + "follow_location", + "last_address", + "last_what3words", + "last_nearest_place" + ) + SELECT + "id", + "user_id", + "phone_number_id", + "device_id", + "location", + "alert_tag", + "created_at", + "call_emergency", + "notify_around", + "notify_relatives", + "level", + "subject", + "accuracy", + "altitude", + "altitude_accuracy", + "heading", + "speed", + "radius", + "address", + "what3words", + "nearest_place", + "uuid", + "code", + "notified_count", + "closed_at", + "keep_open_at", + "updated_at", + "suggest_close_sent", + "suggest_keep_open_sent", + "closed_by", + "emergency_calling_notification_sent", + "acknowledged_relative_count", + "acknowledged_around_count", + "acknowledged_connect_count", + "alerting_relative_count", + "alerting_around_count", + "alerting_connect_count", + "initial_location", + "follow_location", + "last_address", + "last_what3words", + "last_nearest_place" + FROM "alert" + WHERE "id" = p_id + RETURNING "id" INTO v_archived_alert_id; + + -- Insert related alerted records into the archived_alerted table + INSERT INTO + "alerted" ( + "archived_alert_id", + "user_id", + "opened_once", + "created_at", + "near_location", + "opened", + "device_id", + "initial_location", + "notification_sent", + "notification_sent_at", + "initial_distance", + "geomatch_method", + "reason", + "updated_at", + "coming_help", + "relative_user_id" + ) + SELECT + v_archived_alert_id, + "user_id", + "opened_once", + "created_at", + "near_location", + "opened", + "device_id", + "initial_location", + "notification_sent", + "notification_sent_at", + "initial_distance", + "geomatch_method", + "reason", + "updated_at", + "coming_help", + "relative_user_id" + FROM "alerting" + WHERE "alert_id" = p_id; + + -- Insert related messages into the archived_message table + INSERT INTO archived_message ( + "archived_alert_id", + "user_id", + "device_id", + "content_type", + "text", + "audio_file_uuid", + "location", + "created_at" + ) + SELECT + v_archived_alert_id, + "user_id", + "device_id", + "content_type", + "text", + "audio_file_uuid", + "location", + "created_at" + FROM "message" + WHERE "alert_id" = p_id; + + -- Delete the messages from the message table + DELETE FROM "message" + WHERE "alert_id" = p_id; + + -- Delete the alert from the alert table + DELETE FROM "alert" + WHERE id = p_id; + +END; +$function$;