Files
njts-accounting-core/check_db_schema.py
2026-02-20 15:47:27 +09:00

54 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
import psycopg
try:
conn = psycopg.connect(
host='192.168.0.61',
port=55432,
dbname='njts_acct',
user='njts_app',
password='njts_app2025'
)
with conn.cursor() as cur:
# 查看 journal_entries 表的所有列
cur.execute("""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'journal_entries'
ORDER BY ordinal_position
""")
cols = cur.fetchall()
print("journal_entries 表的所有列:")
print("-" * 50)
for col in cols:
print(f'{col[0]:25} {col[1]}')
print("\n版本追踪字段检查:")
print("-" * 50)
cur.execute("""
SELECT COUNT(*) as cnt
FROM information_schema.columns
WHERE table_name = 'journal_entries'
AND column_name IN ('is_latest', 'revision_count', 'original_entry_id')
""")
count = cur.fetchone()[0]
print(f"版本追踪字段存在: {count}/3")
# 检查 test元 的数据
print("\n【test元】仕訳数据检查")
print("-" * 50)
cur.execute("""
SELECT journal_entry_id, entry_date, description,
is_latest, revision_count, original_entry_id
FROM journal_entries
WHERE description LIKE '%test%'
ORDER BY journal_entry_id
""")
rows = cur.fetchall()
for row in rows:
print(row)
conn.close()
except Exception as e:
print(f'错误: {e}')