微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
45
scripts/ops/_check_ods_settlement_fields.py
Normal file
45
scripts/ops/_check_ods_settlement_fields.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
检查 ODS settlement_records 表的字段名
|
||||
"""
|
||||
|
||||
import os
|
||||
import psycopg2
|
||||
from dotenv import load_dotenv
|
||||
|
||||
def main():
|
||||
# 加载环境变量
|
||||
load_dotenv()
|
||||
|
||||
test_db_dsn = os.environ.get('TEST_DB_DSN')
|
||||
if not test_db_dsn:
|
||||
raise RuntimeError("TEST_DB_DSN 环境变量未设置")
|
||||
|
||||
print("🔍 检查 ODS settlement_records 表字段")
|
||||
|
||||
with psycopg2.connect(test_db_dsn) as conn:
|
||||
with conn.cursor() as cur:
|
||||
# 查看表字段
|
||||
cur.execute("""
|
||||
SELECT column_name, data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'ods'
|
||||
AND table_name = 'settlement_records'
|
||||
ORDER BY ordinal_position
|
||||
""")
|
||||
|
||||
columns = cur.fetchall()
|
||||
print(f"settlement_records 表有 {len(columns)} 个字段:")
|
||||
|
||||
for column_name, data_type in columns:
|
||||
print(f" {column_name} ({data_type})")
|
||||
|
||||
# 如果是 ID 相关字段,显示一些样本值
|
||||
if 'id' in column_name.lower():
|
||||
cur.execute(f"SELECT {column_name} FROM ods.settlement_records LIMIT 3")
|
||||
samples = cur.fetchall()
|
||||
sample_values = [str(row[0]) for row in samples]
|
||||
print(f" 样本值: {', '.join(sample_values)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user