-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_demo_names.py
More file actions
34 lines (28 loc) · 1.18 KB
/
update_demo_names.py
File metadata and controls
34 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from sqlalchemy import create_engine, Column, Integer, String, Boolean
from sqlalchemy.orm import sessionmaker, declarative_base
Base = declarative_base()
class Sensor(Base):
__tablename__ = "sensors"
id = Column(Integer, primary_key=True, index=True)
unique_id = Column(String, unique=True, index=True)
name = Column(String)
type = Column(String)
is_hidden = Column(Boolean, default=False)
# Connect to the database
SQLALCHEMY_DATABASE_URL = "sqlite:///./backend/matter_logger.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()
# Find demo sensors
demo_sensors = db.query(Sensor).filter(Sensor.unique_id.like("demo-%")).all()
print(f"Found {len(demo_sensors)} demo sensors to update:")
for sensor in demo_sensors:
old_name = sensor.name
# Add (Demo) suffix if not already present
if not sensor.name.endswith(" (Demo)"):
sensor.name = sensor.name + " (Demo)"
print(f" ID {sensor.id}: '{old_name}' -> '{sensor.name}'")
else:
print(f" ID {sensor.id}: '{sensor.name}' (already has suffix)")
db.commit()
print("\nDatabase updated successfully!")