微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
45
scripts/ops/_check_ods_tables.py
Normal file
45
scripts/ops/_check_ods_tables.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
检查 ODS schema 中的表名
|
||||
"""
|
||||
|
||||
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 schema 中的表")
|
||||
|
||||
with psycopg2.connect(test_db_dsn) as conn:
|
||||
with conn.cursor() as cur:
|
||||
# 查看 ODS schema 中的所有表
|
||||
cur.execute("""
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'ods'
|
||||
AND table_type = 'BASE TABLE'
|
||||
ORDER BY table_name
|
||||
""")
|
||||
|
||||
tables = cur.fetchall()
|
||||
print(f"找到 {len(tables)} 个 ODS 表:")
|
||||
|
||||
for table in tables:
|
||||
table_name = table[0]
|
||||
print(f" {table_name}")
|
||||
|
||||
# 如果是结算相关的表,显示记录数
|
||||
if 'settle' in table_name.lower() or 'order' in table_name.lower():
|
||||
cur.execute(f"SELECT COUNT(*) FROM ods.{table_name}")
|
||||
count = cur.fetchone()[0]
|
||||
print(f" -> {count:,} 条记录")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user