27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
# Assuming db and models (Course) are initialized/imported
|
|
from .models import db, Course
|
|
|
|
def seed_courses():
|
|
course_data = [
|
|
{'id': 1, 'folder': 'grnvs25', 'name': 'GRNVS Tutorium SS 25'},
|
|
{'id': 2, 'folder': 'itsec2526', 'name': 'IT-Sec Tutorium WS 25/26'},
|
|
]
|
|
|
|
for data in course_data:
|
|
# Check if the course already exists by ID
|
|
existing_course = db.session.get(Course, data['id'])
|
|
|
|
if existing_course is None:
|
|
# Create a new Course object if it doesn't exist
|
|
new_course = Course(name=data['name'], folder=data['folder'])
|
|
# Since you're specifying the ID, you need to set it manually
|
|
# if it's not an autoincrement sequence (SQLite handles this fine)
|
|
new_course.id = data['id']
|
|
db.session.add(new_course)
|
|
|
|
# If it exists, you might want to update the name:
|
|
elif existing_course.name != data['name']:
|
|
existing_course.name = data['name']
|
|
|
|
db.session.commit()
|