Updata2
This commit is contained in:
35
etl_billiards/scripts/run_seed_dws_config.py
Normal file
35
etl_billiards/scripts/run_seed_dws_config.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""执行DWS配置数据导入"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
import psycopg2
|
||||
|
||||
def main():
|
||||
# 加载.env配置
|
||||
env_path = Path(__file__).parent.parent / ".env"
|
||||
load_dotenv(env_path)
|
||||
|
||||
dsn = os.getenv("PG_DSN")
|
||||
if not dsn:
|
||||
print("错误: 未找到 PG_DSN 配置")
|
||||
return
|
||||
|
||||
# 读取SQL文件
|
||||
sql_file = Path(__file__).parent.parent / "database" / "seed_dws_config.sql"
|
||||
sql_content = sql_file.read_text(encoding="utf-8")
|
||||
|
||||
print(f"连接数据库...")
|
||||
conn = psycopg2.connect(dsn)
|
||||
conn.autocommit = True
|
||||
|
||||
with conn.cursor() as cur:
|
||||
print(f"执行SQL文件: {sql_file}")
|
||||
cur.execute(sql_content)
|
||||
print("DWS配置数据导入成功!")
|
||||
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user