e-Learning-by-SSE / nm-self-learning

https://staging.sse.uni-hildesheim.de/selflearn
3 stars 4 forks source link

fix(demoSeed): fixed false position of default license #123

Closed lukas-png closed 5 months ago

lukas-png commented 7 months ago

Title: Fix Foreign Key Constraint Error by Ensuring Default License ID

Description:

This pull request addresses a critical issue where our seeding function encounters a foreign key constraint error due to the absence of a default license with ID 0. Our seeding logic mandates the existence of a default license, specifically identified by ID 0. This default license is crucial for the seeding process, as it is automatically assigned to newly created lessons where no specific license ID is provided.

Previously, the lack of a default license with the expected ID 0 in the database led to foreign key constraint violations, disrupting the seeding process. This issue was identified during the execution of our seeding function, which explicitly refers to the default license ID 0 for lessons that do not have a specific license assigned.

lukas-png commented 6 months ago

Kann man das anders hinkriegen? Prisma kümmert sich um die auto-increments automatisch sobald man keine IDs anlegt. Sobald hier eine spezifiziert wird, gibt es das Problem, dass in einer neuen Installation beim ersten mal keine Lizenz angelegt werden kann.

Idee ist, dass anders auf die Default License referenziert wird.

ich könnte die id der default license nach dem erstellen zwischen speichern.

spark-sse commented 6 months ago

Das wäre eine option.

Wo wird die Lizenz benötigt? Kannst du die Code-Stelle einmal verlinken?

lukas-png commented 6 months ago

Das wäre eine option.

Wo wird die Lizenz benötigt? Kannst du die Code-Stelle einmal verlinken?

In seed-functions -> seedCaseStudy

    const courseData: Prisma.CourseCreateManyInput[] = courses.map(c => c.data);
    await prisma.course.createMany({ data: courseData });
    console.log(" - %s\x1b[32m ✔\x1b[0m", "Courses");

    await prisma.lesson.createMany({
        data: chapters.flatMap(chapter =>
            chapter.content.map(lesson => ({
                ...lesson,
                licenseId: lesson.licenseId ?? 0
            }))
        )
    });
    console.log(" - %s\x1b[32m ✔\x1b[0m", "Lessons");

Die 0 ist die genaue Stelle

spark-sse commented 6 months ago

Alles klar. Ist es sehr aufwendig die defaultLicense in einer konstanten zu speichern und zu exportieren? Die würde dann den Chaptern entsprechend zugewiesen werden. So braucht mann dann in den seedFunctions den map nicht mehr.

lukas-png commented 6 months ago

Alles klar. Ist es sehr aufwendig die defaultLicense in einer konstanten zu speichern und zu exportieren? Die würde dann den Chaptern entsprechend zugewiesen werden. So braucht mann dann in den seedFunctions den map nicht mehr.

Du meint dann als globale bzw Module scoped variable ? Dann muss man halt die Default license aus dem create many rausnehmen und einzeln am Anfang hinzufügen

spark-sse commented 6 months ago

module scope