Spaces:
Runtime error
Runtime error
Greg
Claude Opus 4.7 (1M context)
Preparar despliegue en fly.io: monolito dockerizado + seeder demo
6aa6081 Download backend/migrate_data.py from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/migrate_data.py
- Command line
-
hf download hf://spaces/Talosware/talos-access/backend/migrate_data.py
-
curl -L -o migrate_data.py https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/migrate_data.py
1.58 kB
| from app.core.database import SessionLocal | |
| from app.models.section import Section | |
| from app.models.section_subject import SectionSubject | |
| from app.models.teacher_section import TeacherSection | |
| from app.models.teacher_subject import TeacherSubject | |
| from sqlalchemy import text | |
| db = SessionLocal() | |
| # Migrate sections -> section_subjects | |
| sections = db.query(Section).all() | |
| for sec in sections: | |
| existing = db.query(SectionSubject).filter( | |
| SectionSubject.section_id == sec.id, | |
| SectionSubject.subject_id == sec.subject_id | |
| ).first() | |
| if not existing and sec.subject_id: | |
| ss = SectionSubject( | |
| section_id=sec.id, | |
| subject_id=sec.subject_id, | |
| account_id=sec.account_id | |
| ) | |
| db.add(ss) | |
| print(f"SectionSubject: section={sec.id} subject={sec.subject_id}") | |
| # Migrate teacher_sections -> teacher_subjects | |
| ts_list = db.query(TeacherSection).all() | |
| for ts in ts_list: | |
| sec = db.query(Section).filter(Section.id == ts.section_id).first() | |
| if sec and sec.subject_id: | |
| existing = db.query(TeacherSubject).filter( | |
| TeacherSubject.teacher_id == ts.teacher_id, | |
| TeacherSubject.subject_id == sec.subject_id | |
| ).first() | |
| if not existing: | |
| tu = TeacherSubject( | |
| teacher_id=ts.teacher_id, | |
| subject_id=sec.subject_id, | |
| account_id=ts.account_id | |
| ) | |
| db.add(tu) | |
| print(f"TeacherSubject: teacher={ts.teacher_id} subject={sec.subject_id}") | |
| db.commit() | |
| db.close() | |
| print("Migration complete") | |