Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Error while initating pmt init #52

Closed
asaadawey opened this issue Aug 21, 2020 · 12 comments
Closed

Error while initating pmt init #52

asaadawey opened this issue Aug 21, 2020 · 12 comments

Comments

@asaadawey
Copy link

asaadawey commented Aug 21, 2020

Hello , this my first time to use pmt and i cant initaite a pmt

i think there is a typo because the application trying to read from PMT_MANAGMENT_URL
while the created one is MANAGMENT_URL

[](Users\donda\WebstormProjects\new-BackEnd-carRental>pmt init --verbose

  Installing `@prisma-multi-tenant/client` as a dependency in your app...
  $> npm install @prisma-multi-tenant/[email protected]
npm WARN @nexus/[email protected] requires a peer of graphql@^14.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer de
pendencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 but none is installed. You must install peer depend
encies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 14 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer dependencies yoursel
f.
npm WARN [email protected] requires a peer of graphql@^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of aws-lambda@^0.1.2 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 but none is installed. You must install peer dependencies
yourself.
npm WARN [email protected] requires a peer of [email protected] - 14 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @nexus/schema@^0.13.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @prisma/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^14.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.



  We will now configure the management database:

? Management database url: "postgresql://postgres:123456@localhost:5432/postgres?schema=public"

? Are you sure of your inputs? Yes

  Updating .env and schema.prisma files...

  Generating prisma clients for both management and tenants...
  $> node "C:\Users\donda\WebstormProjects\new-BackEnd-carRental\node_modules\@prisma\cli\build\index.js" generate --schema prisma/schema.prisma
Environment variables loaded from provided --schema directory

  $> node "C:\Users\donda\WebstormProjects\new-BackEnd-carRental\node_modules\@prisma\cli\build\index.js" generate

✔ Generated Prisma Client to .\..\..\..\.prisma-multi-tenant\management in 452ms

You can now start using Prisma Client in your code:


import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()


Explore the full API: http://pris.ly/d/client


  Setting up management database...
  $> node "C:\Users\donda\WebstormProjects\new-BackEnd-carRental\node_modules\@prisma\cli\build\index.js" migrate up --create-db  --experimental
Error: P1012

Get config
error: Error validating datasource `management`: The URL for datasource `management` must start with the protocol `file:`.
  -->  schema.prisma:3
   |
 2 |   provider = ["sqlite","mysql","postgresql"]
 3 |   url      = env("PMT_MANAGEMENT_URL")
   |

Validation Error Count: 1


Unknown Error!
Error: Command failed: node "C:\Users\donda\WebstormProjects\new-BackEnd-carRental\node_modules\@prisma\cli\build\index.js" migrate up --create-db  --experimental
Error: P1012

Get config
error: Error validating datasource `management`: The URL for datasource `management` must start with the protocol `file:`.
  -->  schema.prisma:3
   |
 2 |   provider = ["sqlite","mysql","postgresql"]
 3 |   url      = env("PMT_MANAGEMENT_URL")
   |

Validation Error Count: 1


    at ChildProcess.exithandler (child_process.js:303:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1051:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'node "C:\\Users\\donda\\WebstormProjects\\new-BackEnd-carRental\\node_modules\\@prisma\\cli\\build\\index.js" migrate up --create-db  --experimental'
}

)
@Errorname
Copy link
Owner

Hi 👋
Thank you for reporting this issue and sorry for taking this long to answer 🙏

It looks like you used quotes (") when providing the url of the management, can you try without them ?

@asaadawey
Copy link
Author

asaadawey commented Sep 11, 2020

@Errorname

No any problems sir
Also when trying to initate without qutoes is stucking at "Setting up managment database"

Here is the log

D:\7SSCarRentalProject\New Code\Backend>pmt init --verbose

  Installing `@prisma-multi-tenant/client` as a dependency in your app...
  $> npm install @prisma-multi-tenant/[email protected]
npm WARN @nexus/[email protected] requires a peer of graphql@^14.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer dependenc
ies yourself.
npm WARN [email protected] requires a peer of graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 but none is installed. You must install peer dependencies
yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 14 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of aws-lambda@^0.1.2 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 but none is installed. You must install peer dependencies yoursel
f.
npm WARN [email protected] requires a peer of [email protected] - 14 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @nexus/schema@^0.13.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @prisma/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^14.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.



  We will now configure the management database:

? Management database url: postgresql://postgres:123456@localhost:5432/postgres2?schema=public

? Are you sure of your inputs? Yes

  Updating .env and schema.prisma files...

  Generating prisma clients for both management and tenants...
  $> node "D:\7SSCarRentalProject\New Code\Backend\node_modules\@prisma\cli\build\index.js" generate --schema prisma/schema.prisma
Environment variables loaded from provided --schema directory
┌─────────────────────────────────────────────────────────┐
│                                                         │
│  Update available 2.5.1 -> 2.6.2                        │
│  Run npm i --save-dev @prisma/cli to update             │
│                                                         │
└─────────────────────────────────────────────────────────┘

  $> node "D:\7SSCarRentalProject\New Code\Backend\node_modules\@prisma\cli\build\index.js" generate

✔ Generated Prisma Client to .\..\..\..\.prisma-multi-tenant\management in 649ms

You can now start using Prisma Client in your code:


import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()


Explore the full API: http://pris.ly/d/client


  Setting up management database...
  $> node "D:\7SSCarRentalProject\New Code\Backend\node_modules\@prisma\cli\build\index.js" migrate up --create-db  --experimental

@Errorname
Copy link
Owner

Great for the quotes 👍

You are providing the following url: postgresql://postgres:123456@localhost:5432/postgres2?schema=public. Are you using a different schema for the management database?

Prisma-multi-tenant currently uses the "one tenant = one database" model, which also requires another database for the management. (However, once #40 is implemented, you will be able to use the "one database = multiple tenants")

@asaadawey
Copy link
Author

i haven't even initiated the pmt . i currently using one schema at postgres2 db

here is a photo

e2

here is the .env file

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables

# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://postgres:123456@localhost:5432/postgres2?schema=public"


# The following env variable is used by prisma-multi-tenant

MANAGEMENT_URL=postgresql://postgres:123456@localhost:5432/postgres2?schema=public

i have also tried now to remove the space from the directory
but no chance . still stuck at Setting up managment Database

@Errorname
Copy link
Owner

You need to provide a different schema for the management.

Example:

MANAGEMENT_URL=postgresql://postgres:123456@localhost:5432/postgres2?schema=management

@asaadawey
Copy link
Author

Still same

cloned the public schema to managment schema as shown :-
rt

Log

D:\7SSCarRentalProject\NewCode\Backend>pmt init --verbose

  Installing `@prisma-multi-tenant/client` as a dependency in your app...
  $> npm install @prisma-multi-tenant/[email protected]
npm WARN @nexus/[email protected] requires a peer of graphql@^14.5.0 but none is inst
alled. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x bu
t none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.10.5 || ^0.11.
3 || ^0.12.0 || ^0.13.0 || ^14.0.0 but none is installed. You must install peer d
ependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.9.0 || ^0.10.0 ||
 ^0.11.0 || ^0.12.0 || ^0.13.0 but none is installed. You must install peer depen
dencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but none
 is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 14 but no
ne is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 0.13.x but
 none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.11.0 || ^0.12.0 || ^0
.13.0 || ^14.0.0 but none is installed. You must install peer dependencies yourse
lf.
npm WARN [email protected] requires a peer of graphql@^0.12.0 || ^0.13.0 |
| ^14.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of aws-lambd
a@^0.1.2 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.10.5 || ^0.11.
3 || ^0.12.0 || ^0.13.0 but none is installed. You must install peer dependencies
 yourself.
npm WARN [email protected] requires a peer of [email protected] - 14 but none is
installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @nexus/schema@^0.13.1 but none is
 installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @prisma/[email protected] but n
one is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^14.5.0 but none is insta
lled. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.



  We will now configure the management database:

? Management database url: postgresql://postgres:123456@localhost:5432/postgres2?
schema=management

? Are you sure of your inputs? Yes

  Updating .env and schema.prisma files...

  Generating prisma clients for both management and tenants...
  $> node "D:\7SSCarRentalProject\NewCode\Backend\node_modules\@prisma\cli\build\
index.js" generate --schema prisma/schema.prisma
Environment variables loaded from provided --schema directory

  $> node "D:\7SSCarRentalProject\NewCode\Backend\node_modules\@prisma\cli\build\
index.js" generate

✔ Generated Prisma Client to .\..\..\..\.prisma-multi-tenant\management in 624ms

You can now start using Prisma Client in your code:


import { PrismaClient } from '@prisma/client'
// or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()


Explore the full API: http://pris.ly/d/client


  Setting up management database...
  $> node "D:\7SSCarRentalProject\NewCode\Backend\node_modules\@prisma\cli\build\
index.js" migrate up --create-db  --experimental

@Errorname
Copy link
Owner

You need an empty schema for the management. Prisma-multi-tenant will handle the schema itself using Prisma to create a table to handle your tenants. (Maybe I need to improve the documentation to better explain this)

@asaadawey
Copy link
Author

Yesss

This solves the issue . one last question . how i can add tables in the managment schema ?

@Errorname
Copy link
Owner

Awesome! 😄

Prisma-multi-tenant currently "hides" the management prisma schema, so you would need to manually add tables in the management database.

What would be your use case for this ?

@asaadawey
Copy link
Author

@Errorname
Thank you for your support really appreciated

I will tell you my questions regarding pmt and hopefully i can get answers

i have a multi tenant application with prisma

i need to use this tool to implement the multi-tenancy logic

Now i have initiated a pmt via pmt init
What is the purpose of the managment database ?
Is this schema will be synchronised with the other tenants ?

for example . if i have edited a foreign key in the managment schema
Is all of my tenants will have the same effect ?

@Errorname
Copy link
Owner

Alright, so here is how Prisma-multi-tenant works:

You have a management database (here the "management" postgresql schema). This management db is solely handled by Prisma-multi-tenant. It will only contain the references (name + url) to all of your tenants.

You will also have other databases (=postgresql schema): one for each of your tenant.

To create a new tenant, you simple have to call the pmt new command, which will then ask you the desired name + url of the tenant. After that, prisma-multi-tenant will create the database (=postgresql schema) itself, and add the name+url of the tenant in the management database.

So: 1 db for management + X databases for your tenants.

When you want to migrate all of your tenant's databases at the same time, you can call pmt migrate up which will actually call prisma migrate on each of the tenant's databases, one by one.

I hope I was able to answer your questions 🙂

@asaadawey
Copy link
Author

Yes this clarify it

Thank you so much
this issue can be closed now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants