Coverage for pgsql_upserter / __init__.py: 70.00%
18 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-26 18:15 -0300
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-26 18:15 -0300
1"""PostgreSQL dynamic upsert utility with automatic schema introspection."""
3import logging
5from .config import create_connection_from_env, test_connection, validate_permissions
6from .schema_inspector import inspect_table_schema, TableSchema, ColumnInfo, UniqueConstraint
7from .column_matcher import match_columns
8from .temp_staging import create_temp_table, bulk_insert_to_temp, populate_temp_table, convert_temp_to_permanent
9from .conflict_resolver import (
10 find_conflict_strategy,
11 deduplicate_temp_table,
12 execute_upsert,
13 ConflictStrategy,
14 DeduplicationResult
15)
16from .upsert_engine import (
17 UpsertEngine,
18 UpsertResult,
19 read_csv_to_dict_list,
20)
21from .exceptions import (
22 PgsqlUpserterError,
23 ConnectionError,
24 PermissionError,
25 TableNotFoundError,
26 SchemaIntrospectionError
27)
29# Configure package-level logging
30_package_logger = logging.getLogger(__name__)
31_package_logger.setLevel(logging.INFO)
33# Create console handler if no handlers exist
34if not _package_logger.handlers and not _package_logger.parent.handlers: # type: ignore 34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true
35 console_handler = logging.StreamHandler()
36 console_handler.setLevel(logging.INFO)
37 formatter = logging.Formatter('%(levelname)s - %(message)s')
38 console_handler.setFormatter(formatter)
39 _package_logger.addHandler(console_handler)
41# Disable propagation to prevent duplicate messages when external logging is configured
42_package_logger.propagate = False
45__all__ = [
46 # Main API - Upsert Engine
47 'UpsertEngine',
48 'UpsertResult',
49 'read_csv_to_dict_list',
51 # Connection utilities
52 'create_connection_from_env',
53 'test_connection',
54 'validate_permissions',
56 # Lower-level components
57 'inspect_table_schema',
58 'match_columns',
59 'create_temp_table',
60 'populate_temp_table',
61 'bulk_insert_to_temp',
62 'convert_temp_to_permanent',
64 # Conflict resolution components
65 'find_conflict_strategy',
66 'deduplicate_temp_table',
67 'execute_upsert',
69 # Data classes
70 'TableSchema',
71 'ColumnInfo',
72 'UniqueConstraint',
73 'ConflictStrategy',
74 'DeduplicationResult',
76 # Exceptions
77 'PgsqlUpserterError',
78 'ConnectionError',
79 'PermissionError',
80 'TableNotFoundError',
81 'SchemaIntrospectionError',
82]