3434 ("monitoring_wells" , "monitoring well" ),
3535 ("observation_wells" , "observation well" ),
3636 ("other_things" , "other" ),
37- ("outfalls_wastewater_return_flow" , "outfall of wastewater or return flow" ),
37+ (
38+ "outfalls_wastewater_return_flow" ,
39+ "outfall of wastewater or return flow" ,
40+ ),
3841 ("perennial_streams" , "perennial stream" ),
3942 ("piezometers" , "piezometer" ),
4043 ("production_wells" , "production well" ),
@@ -107,8 +110,11 @@ def _create_latest_depth_view() -> str:
107110 o.observation_datetime,
108111 o.value,
109112 o.measuring_point_height,
110- -- Treat NULL measuring_point_height as 0 when computing depth_to_water_bgs
111- (o.value - COALESCE(o.measuring_point_height, 0)) AS depth_to_water_bgs,
113+ -- Treat NULL measuring_point_height as 0 when computing
114+ -- depth_to_water_bgs.
115+ (
116+ o.value - COALESCE(o.measuring_point_height, 0)
117+ ) AS depth_to_water_bgs,
112118 ROW_NUMBER() OVER (
113119 PARTITION BY fe.thing_id
114120 ORDER BY o.observation_datetime DESC, o.id DESC
@@ -151,7 +157,10 @@ def _create_avg_tds_view() -> str:
151157 SELECT
152158 csi.thing_id,
153159 mc.id AS major_chemistry_id,
154- COALESCE(mc."AnalysisDate", csi."CollectionDate")::date AS observation_date,
160+ COALESCE(
161+ mc."AnalysisDate",
162+ csi."CollectionDate"
163+ )::date AS observation_date,
155164 mc."SampleValue" AS sample_value,
156165 mc."Units" AS units
157166 FROM "NMA_MajorChemistry" AS mc
@@ -193,15 +202,16 @@ def _drop_view_or_materialized_view(view_name: str) -> None:
193202
194203def _create_matview_indexes () -> None :
195204 # Required so REFRESH MATERIALIZED VIEW CONCURRENTLY can run.
205+ avg_tds_index_sql = (
206+ "CREATE UNIQUE INDEX ux_ogc_avg_tds_wells_id " "ON ogc_avg_tds_wells (id)"
207+ )
196208 op .execute (
197209 text (
198210 "CREATE UNIQUE INDEX ux_ogc_latest_depth_to_water_wells_id "
199211 "ON ogc_latest_depth_to_water_wells (id)"
200212 )
201213 )
202- op .execute (
203- text ("CREATE UNIQUE INDEX ux_ogc_avg_tds_wells_id " "ON ogc_avg_tds_wells (id)" )
204- )
214+ op .execute (text (avg_tds_index_sql ))
205215
206216
207217def _create_refresh_function () -> str :
@@ -220,7 +230,11 @@ def _create_refresh_function() -> str:
220230 WHERE schemaname = 'public'
221231 AND matviewname LIKE 'ogc_%'
222232 LOOP
223- matview_fqname := format('%I.%I', matview_record.schemaname, matview_record.matviewname);
233+ matview_fqname := format(
234+ '%I.%I',
235+ matview_record.schemaname,
236+ matview_record.matviewname
237+ );
224238 EXECUTE format('REFRESH MATERIALIZED VIEW %s', matview_fqname);
225239 END LOOP;
226240 END;
@@ -235,10 +249,15 @@ def upgrade() -> None:
235249 required_core = {"thing" , "location" , "location_thing_association" }
236250 existing_tables = set (inspector .get_table_names (schema = "public" ))
237251 if not required_core .issubset (existing_tables ):
238- missing_tables = sorted (t for t in required_core if t not in existing_tables )
252+ missing_tables = sorted (
253+ table_name
254+ for table_name in required_core
255+ if table_name not in existing_tables
256+ )
239257 missing_tables_str = ", " .join (missing_tables )
240258 raise RuntimeError (
241- "Cannot create pygeoapi supporting views. The following required core "
259+ "Cannot create pygeoapi supporting views. "
260+ "The following required core "
242261 f"tables are missing: { missing_tables_str } "
243262 )
244263
@@ -255,7 +274,8 @@ def upgrade() -> None:
255274 )
256275 missing_depth_tables_str = ", " .join (missing_depth_tables )
257276 raise RuntimeError (
258- "Cannot create ogc_latest_depth_to_water_wells. The following required "
277+ "Cannot create ogc_latest_depth_to_water_wells. "
278+ "The following required "
259279 f"tables are missing: { missing_depth_tables_str } "
260280 )
261281 op .execute (text (_create_latest_depth_view ()))
@@ -269,7 +289,11 @@ def upgrade() -> None:
269289 _drop_view_or_materialized_view ("ogc_avg_tds_wells" )
270290 required_tds = {"NMA_MajorChemistry" , "NMA_Chemistry_SampleInfo" }
271291 if not required_tds .issubset (existing_tables ):
272- missing_tds_tables = sorted (t for t in required_tds if t not in existing_tables )
292+ missing_tds_tables = sorted (
293+ table_name
294+ for table_name in required_tds
295+ if table_name not in existing_tables
296+ )
273297 missing_tds_tables_str = ", " .join (missing_tds_tables )
274298 raise RuntimeError (
275299 "Cannot create ogc_avg_tds_wells. The following required "
@@ -288,7 +312,10 @@ def upgrade() -> None:
288312
289313
290314def downgrade () -> None :
291- op .execute (text (f"DROP FUNCTION IF EXISTS public.{ REFRESH_FUNCTION_NAME } ()" ))
315+ drop_refresh_function_sql = (
316+ f"DROP FUNCTION IF EXISTS public.{ REFRESH_FUNCTION_NAME } ()"
317+ )
318+ op .execute (text (drop_refresh_function_sql ))
292319 _drop_view_or_materialized_view ("ogc_avg_tds_wells" )
293320 _drop_view_or_materialized_view ("ogc_latest_depth_to_water_wells" )
294321 for view_id , _ in THING_COLLECTIONS :
0 commit comments