Files
GostGenerator/check_db_structure.py
T

65 lines
2.2 KiB
Python

import sqlite3
import os
db_path = 'build/Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/components.db'
if os.path.exists(db_path):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Получаем список всех таблиц
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = cursor.fetchall()
print("=== ТАБЛИЦЫ В БАЗЕ ДАННЫХ ===")
for table in tables:
print(f"- {table[0]}")
print("\n=== СТРУКТУРА ТАБЛИЦ ===")
for table in tables:
table_name = table[0]
print(f"\n--- {table_name} ---")
cursor.execute(f"PRAGMA table_info({table_name})")
columns = cursor.fetchall()
for col in columns:
print(f" {col[1]} ({col[2]}) - {'NOT NULL' if col[3] else 'NULL'}")
# Проверяем индексы
print("\n=== ИНДЕКСЫ ===")
cursor.execute("SELECT name, sql FROM sqlite_master WHERE type='index'")
indexes = cursor.fetchall()
for idx in indexes:
print(f"- {idx[0]}: {idx[1]}")
# Проверяем внешние ключи
print("\n=== ВНЕШНИЕ КЛЮЧИ ===")
cursor.execute("PRAGMA foreign_key_list(components)")
fk_components = cursor.fetchall()
if fk_components:
print("components:")
for fk in fk_components:
print(f" {fk[3]} -> {fk[2]}.{fk[4]}")
cursor.execute("PRAGMA foreign_key_list(component_properties)")
fk_props = cursor.fetchall()
if fk_props:
print("component_properties:")
for fk in fk_props:
print(f" {fk[3]} -> {fk[2]}.{fk[4]}")
cursor.execute("PRAGMA foreign_key_list(component_variants)")
fk_variants = cursor.fetchall()
if fk_variants:
print("component_variants:")
for fk in fk_variants:
print(f" {fk[3]} -> {fk[2]}.{fk[4]}")
cursor.execute("PRAGMA foreign_key_list(variant_properties)")
fk_var_props = cursor.fetchall()
if fk_var_props:
print("variant_properties:")
for fk in fk_var_props:
print(f" {fk[3]} -> {fk[2]}.{fk[4]}")
conn.close()
else:
print(f"Database file not found: {db_path}")