Skip to content

Commit b976948

Browse files
committed
feat: implement 82k+ device catalog with persistent database
1 parent 96b0b69 commit b976948

7 files changed

Lines changed: 446 additions & 15 deletions

File tree

app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ def __init__(self):
979979
# Initialize global database connection for coverage calculations
980980
from db import connection
981981

982-
connection.initialize_database(in_memory=True)
982+
# Use persistent database for 16k+ device catalog
983+
connection.initialize_database(in_memory=False)
983984

984985
# Theme
985986
self.set_theme(self.prefs.get("theme", "dark")) # apply early

check_db.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import sqlite3
3+
4+
catalog_path = os.path.join(os.path.expanduser("~"), "LV_CAD", "catalog.db")
5+
6+
if os.path.exists(catalog_path):
7+
print(f"Database found at: {catalog_path}")
8+
con = sqlite3.connect(catalog_path)
9+
cur = con.cursor()
10+
11+
# Get all tables
12+
cur.execute("SELECT name FROM sqlite_master WHERE type='table'")
13+
tables = cur.fetchall()
14+
print(f"\nTables: {[t[0] for t in tables]}")
15+
16+
# Count rows in each table
17+
for table in tables:
18+
cur.execute(f"SELECT COUNT(*) FROM {table[0]}")
19+
count = cur.fetchone()[0]
20+
print(f" {table[0]}: {count} rows")
21+
22+
# Sample devices if exists
23+
if any(t[0] == "devices" for t in tables):
24+
cur.execute("SELECT * FROM devices LIMIT 5")
25+
print("\nSample devices:")
26+
for row in cur.fetchall():
27+
print(f" {row}")
28+
29+
con.close()
30+
else:
31+
print(f"Database NOT found at: {catalog_path}")
32+
print("Creating new database with full catalog...")

db/connection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ def initialize_database(in_memory: bool = True):
1515
if in_memory:
1616
_connection = sqlite3.connect(":memory:")
1717
else:
18-
# This path can be configured later
19-
_connection = sqlite3.connect("autofire.db")
18+
# Use catalog database in user's LV_CAD folder
19+
import os
20+
21+
catalog_path = os.path.join(os.path.expanduser("~"), "LV_CAD", "catalog.db")
22+
os.makedirs(os.path.dirname(catalog_path), exist_ok=True)
23+
_connection = sqlite3.connect(catalog_path)
2024

2125
# Set row factory for dict-like access
2226
_connection.row_factory = sqlite3.Row
2327

2428
# Create schema
2529
schema.create_schema_tables(_connection)
2630
coverage_tables.create_tables(_connection)
27-
31+
2832
# Populate with data
2933
loader.seed_demo(_connection)
3034
coverage_tables.populate_tables(_connection)
31-
35+
3236
_connection.commit()
3337

3438

docs/REGRESSION_TRACKING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
**Symptom**: User reports database items are missing
4040

4141
**Root Cause**:
42+
4243
- Two separate database connections existed:
4344
- `db/connection.py` - Used by coverage calculations (in-memory)
4445
- `db/loader.py` - Used by catalog (separate file ~/LV_CAD/catalog.db)
@@ -47,13 +48,15 @@
4748
- Result: Device tables existed but were EMPTY
4849

4950
**Solution Implemented**:
51+
5052
- ✅ Modified `db/connection.py` to call `loader.seed_demo()` during initialization
5153
- ✅ Modified `app/catalog.py` to use shared `db/connection` first
5254
- ✅ Falls back to separate connection if needed
5355
- ✅ Added row_factory for dict-like row access
5456
- ✅ Created regression tests in `tests/regression/test_database_connection.py`
5557

5658
**Verification**:
59+
5760
- Database now contains 6 devices, 3 device types, 1 manufacturer
5861
- Catalog loads 6 devices from database
5962
- Coverage tables properly populated (6 wall, 18 ceiling, 7 strobe)

0 commit comments

Comments
 (0)