feat: migrate configuration to .env environment variables
This commit implements a complete migration from JSON-based configuration to .env environment variables, providing better security and flexibility. Key Changes: - Add python-dotenv dependency for environment variable support - Create config/env_loader.py with type conversion utilities - Add from_env() class methods to all config dataclasses - Update ConfigLoader to prioritize environment variables - Add save_to_env() method for .env file management - Implement database connection factory pattern - Add base DAO and connection classes for better abstraction - Support both SQL Server and MySQL with unified interface - Create migration script (scripts/migrate_to_env.py) - Update GUI to read/write .env files - Add comprehensive migration documentation New Files: - config/env_loader.py - Environment variable loader - db/base_connection.py - Base database connection interface - db/base_dao.py - Base DAO with common utilities - db/connection_factory.py - Factory for creating connections - db/mysql_connection.py - MySQL-specific connection - db/sqlserver_connection.py - SQL Server-specific connection - db/table_name_converter.py - SQL dialect converter - scripts/migrate_to_env.py - Configuration migration tool - docs/ENV_MIGRATION.md - Complete migration guide - .env.example - Environment variable template Testing: - Verified MySQL connection (8.0.44) - Tested all DAO operations - Confirmed 150 tables accessible - Validated configuration loading Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"""
|
||||
默认配置值
|
||||
|
||||
定义所有配置项的默认值。
|
||||
定义所有配置项的默认值,从环境变量加载。
|
||||
"""
|
||||
from config.schema import (
|
||||
ERPConfig,
|
||||
@@ -12,49 +12,14 @@ from config.schema import (
|
||||
ExtractionConfig,
|
||||
ValidationConfig,
|
||||
AppConfig,
|
||||
SQLServerConfig,
|
||||
MySQLConfig,
|
||||
DatabaseType,
|
||||
)
|
||||
|
||||
|
||||
# 默认配置
|
||||
DEFAULT_APP_CONFIG = AppConfig(
|
||||
erp=ERPConfig(
|
||||
url="https://68.11.34.30:8082/",
|
||||
username="BLDpengqiangqiang",
|
||||
password="Cqbld123456.",
|
||||
headless=True,
|
||||
ignore_https_errors=True,
|
||||
auto_close_browser=True,
|
||||
),
|
||||
database=DatabaseConfig(
|
||||
server="192.168.110.114",
|
||||
database="CompanyDB",
|
||||
username="peng",
|
||||
password="Cqbld123456.",
|
||||
driver="ODBC Driver 18 for SQL Server",
|
||||
trust_server_certificate="yes",
|
||||
),
|
||||
paths=PathConfig(
|
||||
data_dir="D:/python/playwrite/data/",
|
||||
production_id_file="ProductionID.txt",
|
||||
default_output="离散备料计划维护_合并.xlsx",
|
||||
validation_output="物料状态校验结果.xlsx",
|
||||
),
|
||||
extraction=ExtractionConfig(
|
||||
batch_size=100,
|
||||
verbose=True,
|
||||
auto_convert=True,
|
||||
merge_batches=True,
|
||||
enable_db_persistence=False, # Disabled by default
|
||||
),
|
||||
validation=ValidationConfig(
|
||||
data_source="database_full",
|
||||
use_database=True,
|
||||
batch_size=2000,
|
||||
enable_crud_operations=False,
|
||||
default_manager="",
|
||||
match_mode="substring",
|
||||
),
|
||||
)
|
||||
# 默认配置 - 从环境变量加载
|
||||
DEFAULT_APP_CONFIG = AppConfig.from_env()
|
||||
|
||||
|
||||
# 兼容旧版本的字典格式
|
||||
|
||||
Reference in New Issue
Block a user