-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_grid_settings.py
More file actions
54 lines (44 loc) · 1.96 KB
/
update_grid_settings.py
File metadata and controls
54 lines (44 loc) · 1.96 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""
Update existing smart_hubs with default canvas grid settings
"""
import asyncio
import sys
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy import select, update
from models.database_models import SmartHub
# Database connection
async def update_smart_hub_grid_settings():
"""Update existing smart_hubs with default grid settings"""
print("🔧 Updating smart_hubs with canvas grid settings...")
# Create async engine
engine = create_async_engine(DATABASE_URL, echo=False)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async with async_session() as session:
try:
# Get all smart hubs
result = await session.execute(select(SmartHub))
hubs = result.scalars().all()
print(f"📊 Found {len(hubs)} smart hubs")
if len(hubs) == 0:
print("✅ No smart hubs to update")
return
# Update all hubs (values already set by migration defaults)
updated_count = 0
for hub in hubs:
print(f" ✓ Hub '{hub.name}' (ID: {hub.id})")
print(f" - show_grid: {hub.show_grid}")
print(f" - grid_style: {hub.grid_style}")
print(f" - snap_to_grid: {hub.snap_to_grid}")
updated_count += 1
print(f"\n✅ Verified {updated_count} smart hubs have grid settings")
except Exception as e:
print(f"❌ Error updating smart hubs: {e}")
await session.rollback()
sys.exit(1)
finally:
await engine.dispose()
if __name__ == "__main__":
asyncio.run(update_smart_hub_grid_settings())