refactor(storage): route project DSNs and remove legacy backends
This commit is contained in:
@@ -5,8 +5,7 @@ import chardet
|
||||
import psycopg
|
||||
from psycopg import sql
|
||||
|
||||
import app.services.project_info as project_info
|
||||
from app.core.config import get_pgconn_string
|
||||
from app.infra.db.project_routing import get_project_pgconn_string
|
||||
from app.services.tjnetwork import read_inp
|
||||
|
||||
|
||||
@@ -15,13 +14,14 @@ from app.services.tjnetwork import read_inp
|
||||
############################################################
|
||||
|
||||
|
||||
def network_update(file_path: str) -> None:
|
||||
def network_update(file_path: str, project_code: str) -> None:
|
||||
"""
|
||||
更新pg数据库中的inp文件
|
||||
:param file_path: inp文件
|
||||
:param project_code: 元数据项目代码
|
||||
:return:
|
||||
"""
|
||||
read_inp("szh", file_path)
|
||||
read_inp(project_code, file_path)
|
||||
|
||||
csv_path = "./history_pattern_flow.csv"
|
||||
|
||||
@@ -51,8 +51,7 @@ def network_update(file_path: str) -> None:
|
||||
if os.path.exists(csv_path):
|
||||
print(f"history_patterns_flows文件存在,开始处理...")
|
||||
|
||||
# 连接到 PostgreSQL 数据库(这里是数据库 "bb")
|
||||
with psycopg.connect(f"dbname={project_info.name} host=127.0.0.1") as conn:
|
||||
with psycopg.connect(get_project_pgconn_string(project_code)) as conn:
|
||||
with conn.cursor() as cur:
|
||||
with open(csv_path, newline="", encoding="utf-8-sig") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
@@ -92,7 +91,7 @@ def submit_scada_info(name: str, coord_id: str) -> None:
|
||||
print(f"检测到的文件编码:{file_encoding}")
|
||||
try:
|
||||
# 动态替换数据库名称
|
||||
conn_string = get_pgconn_string(db_name=name)
|
||||
conn_string = get_project_pgconn_string(db_name=name)
|
||||
|
||||
# 连接到 PostgreSQL 数据库(这里是数据库 "bb")
|
||||
with psycopg.connect(conn_string) as conn:
|
||||
|
||||
Reference in New Issue
Block a user