Prisma Parser - Support Many-to-many relations
Task description
Consider handling implicit many-to-many tables:
model Post {
id Int @id @default(autoincrement())
title String
categories Category[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
}
ref: https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/many-to-many-relations#implicit-many-to-many-relations
For implicit many-to-many, no intermediate tables appear in schema.prisma. How should Liam ERD display implicit intermediate tables?
Options:
- Support
MANY_TO_MANYcardinality type - Display implicit intermediate tables by inference
Background
TODO (Optional)
- [ ]
- [ ]
- [ ]
Additional notes (Optional)
Hi @sasamuku @MH4GF , I am interested in doing this task, please assign me.
@Rakshitg600 We'd be happy to have you work on this π
Display implicit intermediate tables by inference
Can you please proceed with displaying implicit tables?
We want to render the database information accurately as ERD.
Thus, we don't need to support MANY_TO_MANY cardinality type. ref: cardinalitySchema
In the above example:
model Post {
id Int @id @default(autoincrement())
title String
categories Category[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
}
the following migration file will be generated:
-- CreateTable
CREATE TABLE "Post" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Category" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "Category_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_CategoryToPost" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL,
CONSTRAINT "_CategoryToPost_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_CategoryToPost_B_index" ON "_CategoryToPost"("B");
-- AddForeignKey
ALTER TABLE "_CategoryToPost" ADD CONSTRAINT "_CategoryToPost_A_fkey" FOREIGN KEY ("A") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_CategoryToPost" ADD CONSTRAINT "_CategoryToPost_B_fkey" FOREIGN KEY ("B") REFERENCES "Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;
_CategoryToPost which does not appear in the schema.prisma, can you try to render it?
Please let me know if you have any question or suggestion.
Thank you, @sasamuku , for assigning me this issue. I will start working on it today and will get back to you shortly with any questions, suggestions, and progress updates.
looks like a nice issue to work on, can i work on this issue ??
@prakha Great! Give me a moment. Let me check with @Rakshitg600.
Hi @Rakshitg600 How is the progress going? If it's difficult to proceed, would it be okay to assign it to @prakha instead?
@sasamuku yes you may assign it to Prakhar, it is taking me too long to understand the codebase.
@Rakshitg600 Okay, thank you for your hard workπ
@prakha I've changed assignment, please read https://github.com/liam-hq/liam/issues/609#issuecomment-2661855174 first. Thank you!
Hii @sasamuku, i am not able to generate erd using localhost.
https://drive.google.com/file/d/1WZUbkUxdBGo6vmcQrRwKDXoM1H6wLH_l/view?usp=sharing
@prakha
Your local server is running on localhost:3001! Please check it out.
https://github.com/liam-hq/liam/blob/9952d0cd0501a8e6e9aeae618a3ec02eda691732/frontend/apps/app/package.json#L47
when running pnpm dev getting these error.
Is Trigger.dev integration required for local development, or is it optional?
@prakha You're right. Sorry, Please ignore it now.
@MH4GF Thanks. I have one more problem coming while starting the app, it is not running in port 3001, below is the error i am facing when running the command pnpm dev.
@liam-hq/app:dev: β Error: Missing required environment variables: GITHUB_APP_ID, GITHUB_PRIVATE_KEY, GITHUB_WEBHOOK_SECRET
@liam-hq/app:dev: β at Module.register (instrumentation.ts:15:10)
@liam-hq/app:dev: β 13 | const { valid, missing } = validateConfig()
@liam-hq/app:dev: β 14 | if (!valid) {
@liam-hq/app:dev: β > 15 | throw new Error(
@liam-hq/app:dev: β | ^
@liam-hq/app:dev: β 16 | Missing required environment variables: ${missing.join(', ')},
@liam-hq/app:dev: β 17 | )
@liam-hq/app:dev: β 18 | }
@liam-hq/app:dev: β
@liam-hq/app:dev: ββ Done in 21.1s
@liam-hq/app:dev:
Umm, @sasamuku Perhaps validateConfig() only runs with the migration flag enabled.
@prakha For now, can you do your development in @liam-hq/cli?
Perhaps validateConfig() only runs with the migration flag enabled.
I'll do it later todayπ
@prakha Sorry for the inconvenience. You can try the following workaround for now.
1οΈβ£ set below in your .env.local
GITHUB_APP_ID="12345"
GITHUB_PRIVATE_KEY="xxxx"
GITHUB_WEBHOOK_SECRET="xxxxx"
or 2οΈβ£ run below command in your process
export GITHUB_APP_ID="12345" GITHUB_PRIVATE_KEY="xxxx" GITHUB_WEBHOOK_SECRET="xxxxx"
@MH4GF, @sasamuku I have created a pull request. There is some code refactoring left, which I will complete by today.
@MH4GF, @sasamuku I have added the test cases. Could you please review and let me know if anything else is needed?
hii @MH4GF, @sasamuku is there anything else that i need to do??
@prakha Thanks! Give me a minute, I'll review it tomorrow! ππ»
@MH4GF and @sasamuku i was not well this week so i was not able to work. I am creating a new pull request for this issue.
@MH4GF and @sasamuku i have created a new pull request please review. #1038.
resolved: https://github.com/liam-hq/liam/pull/1255