-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_existing_appointments.py
More file actions
42 lines (29 loc) · 1.2 KB
/
Copy pathupdate_existing_appointments.py
File metadata and controls
42 lines (29 loc) · 1.2 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
"""
اسکریپت بهروزرسانی نوبتهای موجود برای اضافه کردن duration_minutes
"""
from database import SessionLocal, init_db
from models import Appointment
def update_appointments():
"""بهروزرسانی نوبتهای موجود"""
db = SessionLocal()
try:
# دریافت همه نوبتها
appointments = db.query(Appointment).all()
updated_count = 0
for appointment in appointments:
# اگر duration_minutes تنظیم نشده، مقدار پیشفرض را تنظیم میکنیم
if not hasattr(appointment, 'duration_minutes') or appointment.duration_minutes is None:
appointment.duration_minutes = 30
updated_count += 1
db.commit()
print(f"✓ {updated_count} نوبت بهروزرسانی شد")
print(f"✓ کل نوبتها: {len(appointments)}")
except Exception as e:
db.rollback()
print(f"❌ خطا: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
init_db() # اطمینان از وجود جداول
update_appointments()