Refactor configuration management and remove deprecated files
- Consolidated database, file source, and field mapping configurations into dedicated modules under the `config` directory. - Removed hardcoded database connection details from `migration.py` and replaced them with imports from the new configuration structure. - Updated `ntfy_utils.py` and `run_incremental_sync.py` to utilize the new configuration imports for cleaner code and better maintainability. - Deleted `update_config.py` as its contents have been integrated into the new configuration files. - Added a new `settings.local.json` for managing permissions related to script execution. - Enhanced the structure of the migration tasks and Excel configurations for better organization and clarity.
This commit is contained in:
85
migration.py
85
migration.py
@@ -3,21 +3,13 @@ import os
|
||||
import shutil
|
||||
import urllib
|
||||
from sqlalchemy import create_engine, text
|
||||
from config import DB_CONFIG, MIGRATION_TASKS, TEMP_DIR
|
||||
import ntfy_utils # 确保该文件在同一目录下
|
||||
|
||||
# ==========================================
|
||||
# 1. 脚本配置 (Configuration)
|
||||
# ==========================================
|
||||
|
||||
# 数据库连接信息
|
||||
DB_CONFIG = {
|
||||
"server": "192.168.110.114",
|
||||
"database": "CompanyDB",
|
||||
"username": "peng",
|
||||
"password": "Cqbld123456.",
|
||||
"driver": "ODBC Driver 18 for SQL Server"
|
||||
}
|
||||
|
||||
# 目标表配置
|
||||
TARGET_DB_SCHEMA = "warehouseOutbound"
|
||||
TARGET_TABLE_NAME = "customerProductType"
|
||||
@@ -31,81 +23,6 @@ SQL_COL_MODEL = "客户型号"
|
||||
|
||||
# 运行参数
|
||||
FORCE_UPDATE = False # 如果设为 True,则无视时间对比,强制更新所有文件
|
||||
TEMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp")
|
||||
|
||||
# 迁移任务清单
|
||||
MIGRATION_TASKS = [
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\往年生产执行卡\生产执行卡2022.xlsm",
|
||||
"year": 2022,
|
||||
"sheet_names": ["Sheet1"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
},
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\往年生产执行卡\生产执行卡2023(1-5月).xlsm",
|
||||
"year": 2023,
|
||||
"sheet_names": ["Sheet1"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
},
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\往年生产执行卡\生产执行卡2023(6月-.xlsm",
|
||||
"year": 2023,
|
||||
"sheet_names": ["Sheet1"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
},
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\往年生产执行卡\生产执行卡2024 6月.xlsm",
|
||||
"year": 2024,
|
||||
"sheet_names": ["重庆数据","北京数据"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
},
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\往年生产执行卡\生产执行卡2024.xlsm",
|
||||
"year": 2024,
|
||||
"sheet_names": ["重庆数据","北京数据"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
},
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\生产执行卡2025年.xlsm",
|
||||
"year": 2025,
|
||||
"sheet_names": ["重庆数据","北京数据"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
},
|
||||
{
|
||||
"file_path": r"\\192.168.110.113\生产执行卡\生产执行卡2026年.xlsm",
|
||||
"year": 2026,
|
||||
"sheet_names": ["重庆数据","北京数据"],
|
||||
"mapping": {
|
||||
"车间号": SQL_COL_WORKSHOP,
|
||||
"工令号": SQL_COL_ORDER,
|
||||
"客户型号": SQL_COL_MODEL
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
# ==========================================
|
||||
# 2. 核心辅助函数
|
||||
|
||||
Reference in New Issue
Block a user