From 0b4ea15e336a6e1a83f6e668f3fa5c86902c7bef Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 19 Nov 2024 12:46:57 +0000 Subject: [PATCH] squash migrations --- .../down.sql | 60 ++++++++++++++++++- .../up.sql | 59 ++++++++++++++++++ .../1732020266380_run_sql_migration/down.sql | 57 ------------------ .../1732020266380_run_sql_migration/up.sql | 58 ------------------ 4 files changed, 118 insertions(+), 116 deletions(-) delete mode 100644 hasura.planx.uk/migrations/1732020266380_run_sql_migration/down.sql delete mode 100644 hasura.planx.uk/migrations/1732020266380_run_sql_migration/up.sql diff --git a/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/down.sql b/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/down.sql index 340894dd90..6552b9af87 100644 --- a/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/down.sql +++ b/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/down.sql @@ -1 +1,59 @@ -alter table "public"."analytics_logs" drop column "has_user_clicked_save" \ No newline at end of file +alter table "public"."analytics_logs" drop column "has_user_clicked_save"; + +CREATE OR REPLACE VIEW "public"."analytics_summary" AS + SELECT a.id AS analytics_id, + al.id AS analytics_log_id, + f.slug AS service_slug, + t.slug AS team_slug, + a.type AS analytics_type, + al.created_at AS analytics_log_created_at, + a.created_at AS analytics_created_at, + ((a.user_agent -> 'os'::text) ->> 'name'::text) AS operating_system, + ((a.user_agent -> 'browser'::text) ->> 'name'::text) AS browser, + ((a.user_agent -> 'platform'::text) ->> 'type'::text) AS platform, + a.referrer, + al.flow_direction, + (al.metadata ->> 'change'::text) AS change_metadata, + (al.metadata ->> 'back'::text) AS back_metadata, + (al.metadata ->> 'selectedUrls'::text) AS selected_urls, + (al.metadata ->> 'flag'::text) AS result_flag, + ((al.metadata -> 'flagSet'::text))::text AS result_flagset, + ((al.metadata -> 'displayText'::text) ->> 'heading'::text) AS result_heading, + ((al.metadata -> 'displayText'::text) ->> 'description'::text) AS result_description, + ((al.metadata -> 'helpTextUseful'::text))::text AS help_text_useful, + CASE + WHEN al.has_clicked_help THEN al.metadata + ELSE NULL::jsonb + END AS help_metadata, + al.user_exit AS is_user_exit, + al.node_type, + al.node_title, + al.has_clicked_help, + al.input_errors, + (date_part('epoch'::text, (al.next_log_created_at - al.created_at)))::numeric(10,1) AS time_spent_on_node_seconds, + a.ended_at AS analytics_ended_at, + ((date_part('epoch'::text, (a.ended_at - a.created_at)) / (60)::double precision))::numeric(10,1) AS time_spent_on_analytics_session_minutes, + al.node_id, + al.allow_list_answers, + ((al.allow_list_answers -> 'proposal.projectType'::text))::text AS proposal_project_type, + ((al.allow_list_answers -> 'application.declaration.connection'::text))::text AS application_declaration_connection, + ((al.allow_list_answers -> 'property.type'::text))::text AS property_type, + ((al.allow_list_answers -> 'drawBoundary.action'::text))::text AS draw_boundary_action, + ((al.allow_list_answers -> 'user.role'::text))::text AS user_role, + ((al.allow_list_answers -> 'property.constraints.planning'::text))::text AS property_constraints_planning, + ((al.allow_list_answers -> 'findProperty.action'::text))::text AS find_property_action, + ((al.allow_list_answers -> 'usedFOIYNPP'::text))::text AS used_foiynpp, + ((al.allow_list_answers -> 'propertyInformation.action'::text))::text AS property_information_action, + ((al.allow_list_answers -> 'planningConstraints.action'::text))::text AS planning_constraints_action, + ((al.allow_list_answers -> '_overrides'::text))::text AS overrides, + ((al.allow_list_answers -> 'rab.exitReason'::text))::text AS rab_exit_reason, + ((al.allow_list_answers -> 'service.type'::text))::text AS pre_app_service_type, + ((al.allow_list_answers -> 'application.information.harmful'::text))::text AS pre_app_harmful_info, + ((al.allow_list_answers -> 'application.information.sensitive'::text))::text AS pre_app_sensitive_info, + (((al.allow_list_answers -> 'application.type'::text) -> 0))::text AS application_type, + FROM (((analytics a + LEFT JOIN analytics_logs al ON ((a.id = al.analytics_id))) + LEFT JOIN flows f ON ((a.flow_id = f.id))) + LEFT JOIN teams t ON ((t.id = f.team_id))); + + GRANT SELECT ON "public"."analytics_summary" TO metabase_read_only; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql b/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql index 06f5b05253..8b08cca965 100644 --- a/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql +++ b/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql @@ -1,2 +1,61 @@ alter table "public"."analytics_logs" add column "has_user_clicked_save" boolean null default 'false'; + +CREATE OR REPLACE VIEW "public"."analytics_summary" AS + SELECT a.id AS analytics_id, + al.id AS analytics_log_id, + f.slug AS service_slug, + t.slug AS team_slug, + a.type AS analytics_type, + al.created_at AS analytics_log_created_at, + a.created_at AS analytics_created_at, + ((a.user_agent -> 'os'::text) ->> 'name'::text) AS operating_system, + ((a.user_agent -> 'browser'::text) ->> 'name'::text) AS browser, + ((a.user_agent -> 'platform'::text) ->> 'type'::text) AS platform, + a.referrer, + al.flow_direction, + (al.metadata ->> 'change'::text) AS change_metadata, + (al.metadata ->> 'back'::text) AS back_metadata, + (al.metadata ->> 'selectedUrls'::text) AS selected_urls, + (al.metadata ->> 'flag'::text) AS result_flag, + ((al.metadata -> 'flagSet'::text))::text AS result_flagset, + ((al.metadata -> 'displayText'::text) ->> 'heading'::text) AS result_heading, + ((al.metadata -> 'displayText'::text) ->> 'description'::text) AS result_description, + ((al.metadata -> 'helpTextUseful'::text))::text AS help_text_useful, + CASE + WHEN al.has_clicked_help THEN al.metadata + ELSE NULL::jsonb + END AS help_metadata, + al.user_exit AS is_user_exit, + al.node_type, + al.node_title, + al.has_clicked_help, + al.input_errors, + (date_part('epoch'::text, (al.next_log_created_at - al.created_at)))::numeric(10,1) AS time_spent_on_node_seconds, + a.ended_at AS analytics_ended_at, + ((date_part('epoch'::text, (a.ended_at - a.created_at)) / (60)::double precision))::numeric(10,1) AS time_spent_on_analytics_session_minutes, + al.node_id, + al.allow_list_answers, + ((al.allow_list_answers -> 'proposal.projectType'::text))::text AS proposal_project_type, + ((al.allow_list_answers -> 'application.declaration.connection'::text))::text AS application_declaration_connection, + ((al.allow_list_answers -> 'property.type'::text))::text AS property_type, + ((al.allow_list_answers -> 'drawBoundary.action'::text))::text AS draw_boundary_action, + ((al.allow_list_answers -> 'user.role'::text))::text AS user_role, + ((al.allow_list_answers -> 'property.constraints.planning'::text))::text AS property_constraints_planning, + ((al.allow_list_answers -> 'findProperty.action'::text))::text AS find_property_action, + ((al.allow_list_answers -> 'usedFOIYNPP'::text))::text AS used_foiynpp, + ((al.allow_list_answers -> 'propertyInformation.action'::text))::text AS property_information_action, + ((al.allow_list_answers -> 'planningConstraints.action'::text))::text AS planning_constraints_action, + ((al.allow_list_answers -> '_overrides'::text))::text AS overrides, + ((al.allow_list_answers -> 'rab.exitReason'::text))::text AS rab_exit_reason, + ((al.allow_list_answers -> 'service.type'::text))::text AS pre_app_service_type, + ((al.allow_list_answers -> 'application.information.harmful'::text))::text AS pre_app_harmful_info, + ((al.allow_list_answers -> 'application.information.sensitive'::text))::text AS pre_app_sensitive_info, + (((al.allow_list_answers -> 'application.type'::text) -> 0))::text AS application_type, + al.has_user_clicked_save + FROM (((analytics a + LEFT JOIN analytics_logs al ON ((a.id = al.analytics_id))) + LEFT JOIN flows f ON ((a.flow_id = f.id))) + LEFT JOIN teams t ON ((t.id = f.team_id))); + + GRANT SELECT ON "public"."analytics_summary" TO metabase_read_only; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1732020266380_run_sql_migration/down.sql b/hasura.planx.uk/migrations/1732020266380_run_sql_migration/down.sql deleted file mode 100644 index 189b862e64..0000000000 --- a/hasura.planx.uk/migrations/1732020266380_run_sql_migration/down.sql +++ /dev/null @@ -1,57 +0,0 @@ -CREATE OR REPLACE VIEW "public"."analytics_summary" AS - SELECT a.id AS analytics_id, - al.id AS analytics_log_id, - f.slug AS service_slug, - t.slug AS team_slug, - a.type AS analytics_type, - al.created_at AS analytics_log_created_at, - a.created_at AS analytics_created_at, - ((a.user_agent -> 'os'::text) ->> 'name'::text) AS operating_system, - ((a.user_agent -> 'browser'::text) ->> 'name'::text) AS browser, - ((a.user_agent -> 'platform'::text) ->> 'type'::text) AS platform, - a.referrer, - al.flow_direction, - (al.metadata ->> 'change'::text) AS change_metadata, - (al.metadata ->> 'back'::text) AS back_metadata, - (al.metadata ->> 'selectedUrls'::text) AS selected_urls, - (al.metadata ->> 'flag'::text) AS result_flag, - ((al.metadata -> 'flagSet'::text))::text AS result_flagset, - ((al.metadata -> 'displayText'::text) ->> 'heading'::text) AS result_heading, - ((al.metadata -> 'displayText'::text) ->> 'description'::text) AS result_description, - ((al.metadata -> 'helpTextUseful'::text))::text AS help_text_useful, - CASE - WHEN al.has_clicked_help THEN al.metadata - ELSE NULL::jsonb - END AS help_metadata, - al.user_exit AS is_user_exit, - al.node_type, - al.node_title, - al.has_clicked_help, - al.input_errors, - (date_part('epoch'::text, (al.next_log_created_at - al.created_at)))::numeric(10,1) AS time_spent_on_node_seconds, - a.ended_at AS analytics_ended_at, - ((date_part('epoch'::text, (a.ended_at - a.created_at)) / (60)::double precision))::numeric(10,1) AS time_spent_on_analytics_session_minutes, - al.node_id, - al.allow_list_answers, - ((al.allow_list_answers -> 'proposal.projectType'::text))::text AS proposal_project_type, - ((al.allow_list_answers -> 'application.declaration.connection'::text))::text AS application_declaration_connection, - ((al.allow_list_answers -> 'property.type'::text))::text AS property_type, - ((al.allow_list_answers -> 'drawBoundary.action'::text))::text AS draw_boundary_action, - ((al.allow_list_answers -> 'user.role'::text))::text AS user_role, - ((al.allow_list_answers -> 'property.constraints.planning'::text))::text AS property_constraints_planning, - ((al.allow_list_answers -> 'findProperty.action'::text))::text AS find_property_action, - ((al.allow_list_answers -> 'usedFOIYNPP'::text))::text AS used_foiynpp, - ((al.allow_list_answers -> 'propertyInformation.action'::text))::text AS property_information_action, - ((al.allow_list_answers -> 'planningConstraints.action'::text))::text AS planning_constraints_action, - ((al.allow_list_answers -> '_overrides'::text))::text AS overrides, - ((al.allow_list_answers -> 'rab.exitReason'::text))::text AS rab_exit_reason, - ((al.allow_list_answers -> 'service.type'::text))::text AS pre_app_service_type, - ((al.allow_list_answers -> 'application.information.harmful'::text))::text AS pre_app_harmful_info, - ((al.allow_list_answers -> 'application.information.sensitive'::text))::text AS pre_app_sensitive_info, - (((al.allow_list_answers -> 'application.type'::text) -> 0))::text AS application_type, - FROM (((analytics a - LEFT JOIN analytics_logs al ON ((a.id = al.analytics_id))) - LEFT JOIN flows f ON ((a.flow_id = f.id))) - LEFT JOIN teams t ON ((t.id = f.team_id))); - - GRANT SELECT ON "public"."analytics_summary" TO metabase_read_only; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1732020266380_run_sql_migration/up.sql b/hasura.planx.uk/migrations/1732020266380_run_sql_migration/up.sql deleted file mode 100644 index 200e2e40ea..0000000000 --- a/hasura.planx.uk/migrations/1732020266380_run_sql_migration/up.sql +++ /dev/null @@ -1,58 +0,0 @@ -CREATE OR REPLACE VIEW "public"."analytics_summary" AS - SELECT a.id AS analytics_id, - al.id AS analytics_log_id, - f.slug AS service_slug, - t.slug AS team_slug, - a.type AS analytics_type, - al.created_at AS analytics_log_created_at, - a.created_at AS analytics_created_at, - ((a.user_agent -> 'os'::text) ->> 'name'::text) AS operating_system, - ((a.user_agent -> 'browser'::text) ->> 'name'::text) AS browser, - ((a.user_agent -> 'platform'::text) ->> 'type'::text) AS platform, - a.referrer, - al.flow_direction, - (al.metadata ->> 'change'::text) AS change_metadata, - (al.metadata ->> 'back'::text) AS back_metadata, - (al.metadata ->> 'selectedUrls'::text) AS selected_urls, - (al.metadata ->> 'flag'::text) AS result_flag, - ((al.metadata -> 'flagSet'::text))::text AS result_flagset, - ((al.metadata -> 'displayText'::text) ->> 'heading'::text) AS result_heading, - ((al.metadata -> 'displayText'::text) ->> 'description'::text) AS result_description, - ((al.metadata -> 'helpTextUseful'::text))::text AS help_text_useful, - CASE - WHEN al.has_clicked_help THEN al.metadata - ELSE NULL::jsonb - END AS help_metadata, - al.user_exit AS is_user_exit, - al.node_type, - al.node_title, - al.has_clicked_help, - al.input_errors, - (date_part('epoch'::text, (al.next_log_created_at - al.created_at)))::numeric(10,1) AS time_spent_on_node_seconds, - a.ended_at AS analytics_ended_at, - ((date_part('epoch'::text, (a.ended_at - a.created_at)) / (60)::double precision))::numeric(10,1) AS time_spent_on_analytics_session_minutes, - al.node_id, - al.allow_list_answers, - ((al.allow_list_answers -> 'proposal.projectType'::text))::text AS proposal_project_type, - ((al.allow_list_answers -> 'application.declaration.connection'::text))::text AS application_declaration_connection, - ((al.allow_list_answers -> 'property.type'::text))::text AS property_type, - ((al.allow_list_answers -> 'drawBoundary.action'::text))::text AS draw_boundary_action, - ((al.allow_list_answers -> 'user.role'::text))::text AS user_role, - ((al.allow_list_answers -> 'property.constraints.planning'::text))::text AS property_constraints_planning, - ((al.allow_list_answers -> 'findProperty.action'::text))::text AS find_property_action, - ((al.allow_list_answers -> 'usedFOIYNPP'::text))::text AS used_foiynpp, - ((al.allow_list_answers -> 'propertyInformation.action'::text))::text AS property_information_action, - ((al.allow_list_answers -> 'planningConstraints.action'::text))::text AS planning_constraints_action, - ((al.allow_list_answers -> '_overrides'::text))::text AS overrides, - ((al.allow_list_answers -> 'rab.exitReason'::text))::text AS rab_exit_reason, - ((al.allow_list_answers -> 'service.type'::text))::text AS pre_app_service_type, - ((al.allow_list_answers -> 'application.information.harmful'::text))::text AS pre_app_harmful_info, - ((al.allow_list_answers -> 'application.information.sensitive'::text))::text AS pre_app_sensitive_info, - (((al.allow_list_answers -> 'application.type'::text) -> 0))::text AS application_type, - al.has_user_clicked_save - FROM (((analytics a - LEFT JOIN analytics_logs al ON ((a.id = al.analytics_id))) - LEFT JOIN flows f ON ((a.flow_id = f.id))) - LEFT JOIN teams t ON ((t.id = f.team_id))); - - GRANT SELECT ON "public"."analytics_summary" TO metabase_read_only; \ No newline at end of file