From f9caec57d156414cd78c797ecc78e85250c7bd74 Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Thu, 7 Jul 2022 12:17:16 -0700 Subject: [PATCH] chore: reporting requirement has expenses computed column --- app/schema/schema.graphql | 21 ++++ app/schema/schema.json | 98 +++++++++++++++++++ .../reporting_requirement_has_expenses.sql | 26 +++++ .../reporting_requirement_has_expenses.sql | 7 ++ schema/sqitch.plan | 1 + .../reporting_requirement_has_expenses.sql | 7 ++ 6 files changed, 160 insertions(+) create mode 100644 schema/deploy/computed_columns/reporting_requirement_has_expenses.sql create mode 100644 schema/revert/computed_columns/reporting_requirement_has_expenses.sql create mode 100644 schema/verify/computed_columns/reporting_requirement_has_expenses.sql diff --git a/app/schema/schema.graphql b/app/schema/schema.graphql index 83836e0345..45941f58df 100644 --- a/app/schema/schema.graphql +++ b/app/schema/schema.graphql @@ -47756,6 +47756,7 @@ type ReportType implements Node { """created by user id""" createdBy: Int + hasExpenses: Boolean """ A globally unique identifier. Can be used in various places throughout the system to identify this single value. @@ -48079,6 +48080,9 @@ input ReportTypeCondition { """Checks for equality with the object’s `createdBy` field.""" createdBy: Int + """Checks for equality with the object’s `hasExpenses` field.""" + hasExpenses: Boolean + """Checks for equality with the object’s `isMilestone` field.""" isMilestone: Boolean @@ -48129,6 +48133,9 @@ input ReportTypeFilter { """Filter by the object’s `createdBy` field.""" createdBy: IntFilter + """Filter by the object’s `hasExpenses` field.""" + hasExpenses: BooleanFilter + """Filter by the object’s `isMilestone` field.""" isMilestone: BooleanFilter @@ -48167,6 +48174,7 @@ input ReportTypeInput { """created by user id""" createdBy: Int + hasExpenses: Boolean """ Boolean value indicates if this report type record is a Milestone. There are several different milestones and this value allows for easier filtering. @@ -48198,6 +48206,7 @@ input ReportTypePatch { """created by user id""" createdBy: Int + hasExpenses: Boolean """ Boolean value indicates if this report type record is a Milestone. There are several different milestones and this value allows for easier filtering. @@ -48405,6 +48414,8 @@ enum ReportTypesOrderBy { CREATED_AT_DESC CREATED_BY_ASC CREATED_BY_DESC + HAS_EXPENSES_ASC + HAS_EXPENSES_DESC IS_MILESTONE_ASC IS_MILESTONE_DESC NAME_ASC @@ -48847,6 +48858,11 @@ type ReportingRequirement implements Node { orderBy: [EmissionIntensityReportsOrderBy!] = [PRIMARY_KEY_ASC] ): EmissionIntensityReportsConnection! + """ + Returns the value of the has_expenses column for the report_type of the given reporting_requirement + """ + hasExpenses: Boolean + """ A globally unique identifier. Can be used in various places throughout the system to identify this single value. """ @@ -49675,6 +49691,9 @@ input ReportingRequirementFilter { """Some related `emissionIntensityReportsByReportingRequirementId` exist.""" emissionIntensityReportsByReportingRequirementIdExist: Boolean + """Filter by the object’s `hasExpenses` field.""" + hasExpenses: BooleanFilter + """ Filter by the object’s `milestoneReportsByReportingRequirementId` relation. """ @@ -49954,6 +49973,8 @@ enum ReportingRequirementsOrderBy { REPORT_TYPE_BY_REPORT_TYPE__CREATED_AT_DESC REPORT_TYPE_BY_REPORT_TYPE__CREATED_BY_ASC REPORT_TYPE_BY_REPORT_TYPE__CREATED_BY_DESC + REPORT_TYPE_BY_REPORT_TYPE__HAS_EXPENSES_ASC + REPORT_TYPE_BY_REPORT_TYPE__HAS_EXPENSES_DESC REPORT_TYPE_BY_REPORT_TYPE__IS_MILESTONE_ASC REPORT_TYPE_BY_REPORT_TYPE__IS_MILESTONE_DESC REPORT_TYPE_BY_REPORT_TYPE__NAME_ASC diff --git a/app/schema/schema.json b/app/schema/schema.json index e02c7b67da..5201162f82 100644 --- a/app/schema/schema.json +++ b/app/schema/schema.json @@ -164283,6 +164283,18 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "hasExpenses", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "id", "description": "A globally unique identifier. Can be used in various places throughout the system to identify this single value.", @@ -165354,6 +165366,16 @@ }, "defaultValue": null }, + { + "name": "hasExpenses", + "description": "Checks for equality with the object’s `hasExpenses` field.", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": null + }, { "name": "isMilestone", "description": "Checks for equality with the object’s `isMilestone` field.", @@ -165523,6 +165545,16 @@ }, "defaultValue": null }, + { + "name": "hasExpenses", + "description": "Filter by the object’s `hasExpenses` field.", + "type": { + "kind": "INPUT_OBJECT", + "name": "BooleanFilter", + "ofType": null + }, + "defaultValue": null + }, { "name": "isMilestone", "description": "Filter by the object’s `isMilestone` field.", @@ -165662,6 +165694,16 @@ }, "defaultValue": null }, + { + "name": "hasExpenses", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": null + }, { "name": "isMilestone", "description": "Boolean value indicates if this report type record is a Milestone. There are several different milestones and this value allows for easier filtering.", @@ -165757,6 +165799,16 @@ }, "defaultValue": null }, + { + "name": "hasExpenses", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": null + }, { "name": "isMilestone", "description": "Boolean value indicates if this report type record is a Milestone. There are several different milestones and this value allows for easier filtering.", @@ -166654,6 +166706,18 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "HAS_EXPENSES_ASC", + "description": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "HAS_EXPENSES_DESC", + "description": null, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "IS_MILESTONE_ASC", "description": null, @@ -168002,6 +168066,18 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "hasExpenses", + "description": "Returns the value of the has_expenses column for the report_type of the given reporting_requirement", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "id", "description": "A globally unique identifier. Can be used in various places throughout the system to identify this single value.", @@ -170848,6 +170924,16 @@ }, "defaultValue": null }, + { + "name": "hasExpenses", + "description": "Filter by the object’s `hasExpenses` field.", + "type": { + "kind": "INPUT_OBJECT", + "name": "BooleanFilter", + "ofType": null + }, + "defaultValue": null + }, { "name": "milestoneReportsByReportingRequirementId", "description": "Filter by the object’s `milestoneReportsByReportingRequirementId` relation.", @@ -172102,6 +172188,18 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "REPORT_TYPE_BY_REPORT_TYPE__HAS_EXPENSES_ASC", + "description": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "REPORT_TYPE_BY_REPORT_TYPE__HAS_EXPENSES_DESC", + "description": null, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "REPORT_TYPE_BY_REPORT_TYPE__IS_MILESTONE_ASC", "description": null, diff --git a/schema/deploy/computed_columns/reporting_requirement_has_expenses.sql b/schema/deploy/computed_columns/reporting_requirement_has_expenses.sql new file mode 100644 index 0000000000..9b72deac86 --- /dev/null +++ b/schema/deploy/computed_columns/reporting_requirement_has_expenses.sql @@ -0,0 +1,26 @@ +-- Deploy cif:computed_columns/reporting_requirement_has_expenses to pg +-- requires: tables/report_type +-- requires: tables/reporting_requirement + +begin; + +create function cif.reporting_requirement_has_expenses(cif.reporting_requirement) +returns boolean as +$computed_column$ + select has_expenses + from cif.report_type + where name = $1.report_type; +$computed_column$ language sql stable; + +comment on function cif.reporting_requirement_has_expenses(cif.reporting_requirement) is + 'Returns the value of the has_expenses column for the report_type of the given reporting_requirement'; + +commit; + +-- create function cif.reporting_requirement_has_expenses(cif.reporting_requirement) +-- returns boolean as +-- $computed_column$ +-- select has_expenses +-- from cif.report_type +-- where name = $1.report_type; +-- $computed_column$ language sql stable; diff --git a/schema/revert/computed_columns/reporting_requirement_has_expenses.sql b/schema/revert/computed_columns/reporting_requirement_has_expenses.sql new file mode 100644 index 0000000000..91624bd537 --- /dev/null +++ b/schema/revert/computed_columns/reporting_requirement_has_expenses.sql @@ -0,0 +1,7 @@ +-- Revert cif:computed_columns/reporting_requirement_has_expenses from pg + +begin; + +drop function cif.reporting_requirement_has_expenses; + +commit; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index df1e86e654..59bc5fa728 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -88,3 +88,4 @@ tables/milestone_report [tables/reporting_requirement] 2022-06-22T21:01:22Z Dyla mutations/add_milestone_to_revision [tables/reporting_requirement tables/form_change] 2022-06-23T23:26:45Z Dylan Leard # A custom mutation chain to create form_change records for multiple tables when creating a milestone mutations/discard_milestone_form_change [tables/form_change tables/project_revision] 2022-06-24T16:25:29Z Dylan Leard # Custom mutation to discard a set of form_change records relating to a milestone_report tables/funding_parameter 2022-06-23T17:34:25Z Gurjeet Matharu # funding parameter table +computed_columns/reporting_requirement_has_expenses [tables/report_type tables/reporting_requirement] 2022-07-06T22:31:55Z Mike Vesprini # Computed column returns true if the report type of the reporting requirement has payments associated with it diff --git a/schema/verify/computed_columns/reporting_requirement_has_expenses.sql b/schema/verify/computed_columns/reporting_requirement_has_expenses.sql new file mode 100644 index 0000000000..74a0c4a96b --- /dev/null +++ b/schema/verify/computed_columns/reporting_requirement_has_expenses.sql @@ -0,0 +1,7 @@ +-- Verify cif:computed_columns/reporting_requirement_has_expenses on pg + +BEGIN; + +select pg_get_functiondef('cif.reporting_requirement_has_expenses(cif.reporting_requirement)'::regprocedure); + +ROLLBACK;