-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(demoSeed): fixed false position of default license #123
Conversation
d0427fc
to
c19f2e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
1cfc8d4
to
da05d2a
Compare
c19f2e2
to
7af30a1
Compare
ich könnte die id der default license nach dem erstellen zwischen speichern. |
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 |
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 |
module scope |
94765ea
to
457096b
Compare
457096b
to
55834f4
Compare
@@ -535,9 +536,13 @@ const completedLessons: Prisma.CompletedLessonCreateManyInput[] = extractLessonI | |||
createdAt: subHours(Date.now(), index * 4) | |||
})); | |||
|
|||
|
|||
export let defaultLicenseID = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutable export variables sind quasi globals
const module = await import ("./demo/demo"); | ||
const defaultLicense = module.defaultLicenseID; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
können wir das irgendwie ohne den lazy import hinkriegen?
…ility' into fix/122-seeding-throws-error # Conflicts: # libs/data-access/database/src/lib/demo/demo.ts # libs/data-access/database/src/lib/seed-functions.ts
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.