From 947053b7bb0e761c18ebddf499b3317b64911e49 Mon Sep 17 00:00:00 2001 From: Vim Date: Tue, 10 Oct 2023 12:35:37 +1300 Subject: [PATCH] water_allocation.meter should correlate with observation_site.name --- .../db/migration/R__water_allocation_and_usage_by_area.sql | 7 ++++++- .../eop/plan_limits/WaterAllocationAndUsageViewsTest.kt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/Manager/src/main/resources/db/migration/R__water_allocation_and_usage_by_area.sql b/packages/Manager/src/main/resources/db/migration/R__water_allocation_and_usage_by_area.sql index 69ac0bcd..47100cbd 100644 --- a/packages/Manager/src/main/resources/db/migration/R__water_allocation_and_usage_by_area.sql +++ b/packages/Manager/src/main/resources/db/migration/R__water_allocation_and_usage_by_area.sql @@ -33,6 +33,11 @@ effective_consents_with_defaults as ( from effective_daily_consents where area_id is not null and status = 'active' ), +observed_water_use_with_sites as ( + select owu.*, os.name as site_name + from observed_water_use_aggregated_daily owu + inner join observation_sites os on os.id = owu.site_id +), expanded_meters_per_area as (select effective_on, area_id, UNNEST(meters) as meter from effective_consents_with_defaults where is_metered = true), meter_use_by_area as (select effective_on, @@ -40,7 +45,7 @@ meter_use_by_area as (select effective_on, meter, use.daily_usage from expanded_meters_per_area - left join observed_water_use_aggregated_daily use on effective_on = day_observed_at and meter = site_id::varchar), + left join observed_water_use_with_sites use on effective_on = day_observed_at and meter = site_name), total_daily_use_by_area as (select area_id, effective_on as date, SUM(daily_usage) as daily_usage diff --git a/packages/Manager/src/test/kotlin/nz/govt/eop/plan_limits/WaterAllocationAndUsageViewsTest.kt b/packages/Manager/src/test/kotlin/nz/govt/eop/plan_limits/WaterAllocationAndUsageViewsTest.kt index 55c395cc..3efa8006 100644 --- a/packages/Manager/src/test/kotlin/nz/govt/eop/plan_limits/WaterAllocationAndUsageViewsTest.kt +++ b/packages/Manager/src/test/kotlin/nz/govt/eop/plan_limits/WaterAllocationAndUsageViewsTest.kt @@ -402,7 +402,7 @@ class WaterAllocationAndUsageViewsTest(@Autowired val jdbcTemplate: JdbcTemplate jdbcTemplate.update( """ INSERT INTO observation_sites (id, council_id, name) - VALUES ($siteId, $councilId, 'Test site $siteId') + VALUES ($siteId, $councilId, '$siteId') ON CONFLICT (id) DO NOTHING """)