liam icon indicating copy to clipboard operation
liam copied to clipboard

Prisma Parser - Support Many-to-many relations

Open sasamuku opened this issue 11 months ago β€’ 22 comments

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_MANY cardinality type
  • Display implicit intermediate tables by inference

Background

TODO (Optional)

  • [ ]
  • [ ]
  • [ ]

Additional notes (Optional)

sasamuku avatar Jan 29 '25 02:01 sasamuku

Hi @sasamuku @MH4GF , I am interested in doing this task, please assign me.

Rakshitg600 avatar Feb 14 '25 15:02 Rakshitg600

@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.

sasamuku avatar Feb 17 '25 03:02 sasamuku

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.

Rakshitg600 avatar Feb 17 '25 07:02 Rakshitg600

looks like a nice issue to work on, can i work on this issue ??

prakha avatar Mar 12 '25 20:03 prakha

@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 avatar Mar 13 '25 03:03 sasamuku

@sasamuku yes you may assign it to Prakhar, it is taking me too long to understand the codebase.

Rakshitg600 avatar Mar 13 '25 04:03 Rakshitg600

@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!

sasamuku avatar Mar 13 '25 05:03 sasamuku

Hii @sasamuku, i am not able to generate erd using localhost.

https://drive.google.com/file/d/1WZUbkUxdBGo6vmcQrRwKDXoM1H6wLH_l/view?usp=sharing

prakha avatar Mar 17 '25 07:03 prakha

@prakha Your local server is running on localhost:3001! Please check it out.

Image

https://github.com/liam-hq/liam/blob/9952d0cd0501a8e6e9aeae618a3ec02eda691732/frontend/apps/app/package.json#L47

sasamuku avatar Mar 17 '25 07:03 sasamuku

when running pnpm dev getting these error.

Image

prakha avatar Mar 17 '25 13:03 prakha

Is Trigger.dev integration required for local development, or is it optional?

prakha avatar Mar 17 '25 17:03 prakha

@prakha You're right. Sorry, Please ignore it now.

MH4GF avatar Mar 18 '25 00:03 MH4GF

@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:

prakha avatar Mar 18 '25 04:03 prakha

Umm, @sasamuku Perhaps validateConfig() only runs with the migration flag enabled.


@prakha For now, can you do your development in @liam-hq/cli?

MH4GF avatar Mar 18 '25 05:03 MH4GF

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"

sasamuku avatar Mar 18 '25 05:03 sasamuku

@MH4GF, @sasamuku I have created a pull request. There is some code refactoring left, which I will complete by today.

prakha avatar Mar 21 '25 00:03 prakha

@MH4GF, @sasamuku I have added the test cases. Could you please review and let me know if anything else is needed?

prakha avatar Mar 23 '25 21:03 prakha

hii @MH4GF, @sasamuku is there anything else that i need to do??

prakha avatar Mar 24 '25 08:03 prakha

@prakha Thanks! Give me a minute, I'll review it tomorrow! πŸ‘πŸ»

MH4GF avatar Mar 24 '25 11:03 MH4GF

@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.

prakha avatar Mar 29 '25 00:03 prakha

@MH4GF and @sasamuku i have created a new pull request please review. #1038.

prakha avatar Mar 29 '25 23:03 prakha

Image

prakha avatar Mar 29 '25 23:03 prakha

resolved: https://github.com/liam-hq/liam/pull/1255

MH4GF avatar May 13 '25 03:05 MH4GF