Errorname / prisma-multi-tenant

🧭 Use Prisma as a multi-tenant provider for your application
MIT License
395 stars 45 forks source link

Allow --schema parameter on tenant generate #47

Closed kringt06 closed 4 years ago

kringt06 commented 4 years ago

Now I want to pass through prisma generate --schema="***" to implement custom directories. (schema.prisma)

But....code....

  async generateTenants(prismaArgs = '') {
    const schemaPath = await getSchemaPath()
    await runDistantPrisma(`generate ${prismaArgs} --schema ${schemaPath}`)
  }

You can open the parameters?

like this

npx prisma-multi-tenant generate -- --schema=\"./prisma/schemas/one.prisma\""

....

Errorname commented 4 years ago

Hi, thank you for raising this issue!

This would indeed be better to allow to pass --schema when generating tenants. I'll try to work on this feature request, and implement it for the next release of prisma-multi-tenant (probably this week end)

Errorname commented 4 years ago

The --schema has been implemented and released in prisma-multi-tenant@2.3.1

kringt06 commented 4 years ago

runLocal Error:

const sharedPath = await findUp('node_modules/@prisma-multi-tenant/shared/build')

// return =>  sharedPath = undefined

Lead to

Unknown Error!
Error: Command failed: node "/Users/xxx/node_modules/@prisma/cli/build/index.js" generate
Environment variables loaded from prisma/.env
Error: Either provide --schema or make sure that you are in a folder with a schema.prisma file.
Errorname commented 4 years ago

What command where you running ? Does @prisma-multi-tenant/shared is present in your node_modules ? (It should be a dependency of @prisma-multi-tenant/client)

kringt06 commented 4 years ago

RUN npm run gen....... package.json scripts => npx prisma-multi-tenant generate --schema=\"./prisma/one.prisma\"

"dependencies": {
 "prisma-multi-tenant": "2.3.1",
    "@prisma-multi-tenant/client": "2.3.1",
    "@prisma-multi-tenant/shared": "2.3.1"
}

There are ‘< project >/node_modules/@prisma-multi-tenant/shared ’

Errorname commented 4 years ago

Can you try removing "npx" in the npm script ?

kringt06 commented 4 years ago

Error again!

Errorname commented 4 years ago

Unfortunately, I am not able to reproduce. Can you make a small reproduction repository so that I can take a look?

kringt06 commented 4 years ago

I think the problem may be related to the pnpm install. I've adjusted the dependencies, and that's OK.

But you might want to look at why is the pnpm problematic.

https://github.com/364734461/pmt-test

RUN examples/prisma-cli-404 -> npm run generate -> will Error: Cannot find @prisma/cli

RUN examples/pmt -> npm run generate -> will Error: Command failed: node "/Users/xxx/pmt-test/examples/pmt/node_modules/@prisma/cli/build/index.js" generate Environment variables loaded from prisma/.env Error: Either provide --schema or make sure that you are in a folder with a schema.prisma file.

Errorname commented 4 years ago

Great to hear it's working for you.

Yes, it looks like pnpm is doing something that prisma-multi-tenant isn't built to handle. I'll probably look at how Prisma handled this