Files
getDomain/domainCheck/check_database.py
2026-04-16 13:33:06 +08:00

74 lines
1.9 KiB
Python

# -*- coding: UTF-8 -*-
'''
@Project :domainScanDemo
@File :check_database.py
@IDE :PyCharm
@Author :梦伴
@Date :2026/4/9 21:40
@explain : 检查数据库表结构和注释
'''
import psycopg2
from app.config import config
def check_database():
"""
检查数据库表结构和注释
"""
try:
# 连接数据库
conn = psycopg2.connect(
host=config.DB_HOST,
port=config.DB_PORT,
database=config.DB_DATABASE,
user=config.DB_USER,
password=config.DB_PASSWORD
)
cur = conn.cursor()
print("数据库连接成功")
# 检查所有表
print("\n=== 所有表 ===")
cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
tables = cur.fetchall()
for table in tables:
print(f"表名: {table[0]}")
# 检查domains表结构
print("\n=== domains表结构 ===")
cur.execute("\d+ domains.txt")
result = cur.fetchall()
for row in result:
print(row)
# 检查其他表结构
print("\n=== detect_tasks表结构 ===")
cur.execute("\d+ detect_tasks")
result = cur.fetchall()
for row in result:
print(row)
print("\n=== domain_blacklist表结构 ===")
cur.execute("\d+ domain_blacklist")
result = cur.fetchall()
for row in result:
print(row)
print("\n=== domain_detections表结构 ===")
cur.execute("\d+ domain_detections")
result = cur.fetchall()
for row in result:
print(row)
except Exception as e:
print(f"检查数据库失败: {e}")
finally:
if cur:
cur.close()
if conn:
conn.close()
if __name__ == "__main__":
check_database()