11"""Module to interact with Postgres database.
2+
3+ Dynamic SQL is used in this module to allow customized schema names for storing
4+ data. At a glance, this is vulnerable to SQLi (SQL Injection) considering the
5+ ``schema_name`` variable is technically "user input". This is not considered
6+ a concern for this project because the user inputting the ``schema_name`` value
7+ is considered a trusted user.
28"""
39import logging
410import os
@@ -607,7 +613,7 @@ def run_pg_dump(export_path, skip_qgis_style):
607613 fix_pg_dump_create_public (export_path )
608614
609615
610- def fix_pg_dump_create_public (export_path ):
616+ def fix_pg_dump_create_public (export_path : str ):
611617 """Using pg_dump with `--schema=public` results in
612618 a .sql script containing `CREATE SCHEMA public;`, nearly always breaks
613619 in target DB. Replaces with `CREATE SCHEMA IF NOT EXISTS public;`
@@ -623,10 +629,10 @@ def fix_pg_dump_create_public(export_path):
623629 LOGGER .debug (result )
624630
625631
626- def log_import_message (import_id , msg , schema_name ):
632+ def log_import_message (import_id : int , msg : str , schema_name : str ):
627633 """Logs msg to database in osm.pgosm_flex for import_uuid.
628634
629- Overwrites `osm_date` IF `pbf_timestamp` is set.
635+ Overwrites `osm_date` if `pbf_timestamp` is set.
630636
631637 Parameters
632638 -------------------------------
@@ -638,6 +644,7 @@ def log_import_message(import_id, msg, schema_name):
638644 pbf_timestamp = os .environ ['PBF_TIMESTAMP' ]
639645 except KeyError :
640646 pbf_timestamp = os .environ ['PGOSM_DATE' ]
647+
641648 sql_raw = """
642649UPDATE {schema_name}.pgosm_flex
643650 SET import_status = %(msg)s ,
0 commit comments