Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rustprooflabs committed Jul 6, 2024
1 parent 4510d5c commit 20f91a5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docker/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
"""Module to interact with Postgres database.
Dynamic SQL is used in this module to allow customized schema names for storing
data. At a glance, this is vulnerable to SQLi (SQL Injection) considering the
``schema_name`` variable is technically "user input". This is not considered
a concern for this project because the user inputting the ``schema_name`` value
is considered a trusted user.
"""
import logging
import os
Expand Down Expand Up @@ -607,7 +613,7 @@ def run_pg_dump(export_path, skip_qgis_style):
fix_pg_dump_create_public(export_path)


def fix_pg_dump_create_public(export_path):
def fix_pg_dump_create_public(export_path: str):
"""Using pg_dump with `--schema=public` results in
a .sql script containing `CREATE SCHEMA public;`, nearly always breaks
in target DB. Replaces with `CREATE SCHEMA IF NOT EXISTS public;`
Expand All @@ -623,10 +629,10 @@ def fix_pg_dump_create_public(export_path):
LOGGER.debug(result)


def log_import_message(import_id, msg, schema_name):
def log_import_message(import_id: int, msg: str, schema_name: str):
"""Logs msg to database in osm.pgosm_flex for import_uuid.
Overwrites `osm_date` IF `pbf_timestamp` is set.
Overwrites `osm_date` if `pbf_timestamp` is set.
Parameters
-------------------------------
Expand All @@ -638,6 +644,7 @@ def log_import_message(import_id, msg, schema_name):
pbf_timestamp = os.environ['PBF_TIMESTAMP']
except KeyError:
pbf_timestamp = os.environ['PGOSM_DATE']

sql_raw = """
UPDATE {schema_name}.pgosm_flex
SET import_status = %(msg)s ,
Expand Down

0 comments on commit 20f91a5

Please sign in to comment.