This commit is contained in:
+15
-2
@@ -111,7 +111,9 @@ class NFOGuardDatabase:
|
||||
else:
|
||||
self._init_sqlite_tables(cursor)
|
||||
|
||||
print(f"✅ Database initialized: {self.db_type.upper()}")
|
||||
# Test the connection works
|
||||
cursor.execute("SELECT 1")
|
||||
print(f"✅ Database initialized and connection verified: {self.db_type.upper()}")
|
||||
|
||||
def _init_postgresql_tables(self, cursor):
|
||||
"""Initialize PostgreSQL tables"""
|
||||
@@ -464,6 +466,16 @@ class NFOGuardDatabase:
|
||||
cursor.execute("SELECT COUNT(*) FROM processing_history")
|
||||
history_count = self._get_first_value(cursor.fetchone())
|
||||
|
||||
# Database size calculation
|
||||
if self.db_type == "postgresql":
|
||||
# PostgreSQL: Query pg_database_size
|
||||
cursor.execute("SELECT pg_database_size(%s)", (self.db_name,))
|
||||
db_size_bytes = self._get_first_value(cursor.fetchone())
|
||||
db_size_mb = round(db_size_bytes / 1024 / 1024, 2) if db_size_bytes else 0
|
||||
else:
|
||||
# SQLite: File size
|
||||
db_size_mb = round(self.db_path.stat().st_size / 1024 / 1024, 2)
|
||||
|
||||
return {
|
||||
"series_count": series_count,
|
||||
"episodes_total": episodes_total,
|
||||
@@ -471,7 +483,8 @@ class NFOGuardDatabase:
|
||||
"movies_total": movies_total,
|
||||
"movies_with_video": movies_with_video,
|
||||
"processing_history_count": history_count,
|
||||
"database_size_mb": round(self.db_path.stat().st_size / 1024 / 1024, 2)
|
||||
"database_size_mb": db_size_mb,
|
||||
"database_type": self.db_type
|
||||
}
|
||||
|
||||
def close(self):
|
||||
|
||||
Reference in New Issue
Block a user