Closed Xaedblade closed 4 years ago
Hi @Xaedblade, what versions of prisma-multi-tenant are you using, both globally and locally ? Globally:
prisma-multi-tenant -v
Locally: (open package.json)
@Xaedblade pmt moved its location in node_modules in beta 4. It should work if you import like this: import { PrismaClient as PrismaClientManagement } from '.prisma-multi-tenant/management'
@Errorname I've used the beta.3 version and beta.4 version. @BjoernRave I've not gotten to the point of importing to the project yet, just trying to setup the initial tenant
@Xaedblade Can you try the following steps ?
#1 Update prisma-multi-tenant globally
npm i -g prisma-multi-tenant
#2 Make sure you have the latest version (currently beta.5)
prisma-multi-tenant -v
#3 Run prisma-multi-tenant
prisma-multi-tenant init
Error: Cannot find module '.prisma-multi-tenant/management'.
also, I notice that an index.js page opens up that is based in the @prisma->cli->build
Can you provide the full logs of the prisma-multi-tenant init --verbose
command ?
` Generating prisma clients for both management and tenants... $> "C:\Users\user\Desktop\development\comp\proj\node_modules\@prisma\cli\build\index.js" generate
$> "C:\Users\user\Desktop\development\comp\proj\node_modules\@prisma\cli\build\index.js" generate
Setting up management database... $> "C:\Users\user\Desktop\development\comp\proj\node_modules\@prisma\cli\build\index.js" migrate up --create-db --experimental
Creating first tenant from your initial schema...
Error: Cannot find module '.prisma-multi-tenant/management'.
Try running "prisma-multi-tenant generate"`
Can you try installing the latest release (beta.6): npm i -g prisma-multi-tenant
?
yes I was using the beta6
What happens if you run prisma-multi-tenant generate
?
`$ prisma-multi-tenant generate --verbose
Generating Prisma Clients for both management and tenants... $> "C:\Users\user\Desktop\development\comp\proj\node_modules\@prisma\cli\build\index.js" generate
$> "C:\Users\user\Desktop\development\comp\proj\node_modules\@prisma\cli\build\index.js" generate
โ Prisma Clients have been generated!
`
Is there a .prisma-multi-tenant/management
folder in the node_modules
?
no, there is a "prisma-multi-tenant" folder but not a ".prisma-mulit-tenant"
I have the same problem in Windows :( is there any way to fix it? thanks a lot!
$ prisma-multi-tenant -v
2.1.0
$ prisma-multi-tenant new
? Name of the tenant: t0
? Database provider: sqlite
? Database url: file:t0.db
{ name: 't0', provider: 'sqlite', url: 'file:t0.db' }
? Are you sure of your inputs? Yes
Note: Prisma seems to be unresponsive. Try running `prisma-multi-tenant env t0 -- npx @prisma/cli migrate up --create-db --experimental`
$ prisma-multi-tenant env t0 -- npx @prisma/cli migrate up --create-db --experimental
Running `npx @prisma/cli migrate up --create-db --experimental` on tenant "t0"
Error: Cannot find module '.prisma-multi-tenant/management'.
Try running "prisma-multi-tenant generate"
$ prisma-multi-tenant generate --verbose
Generating Prisma Clients for both management and tenants...
$> "PATH_TO_PROJECT\node_modules\@prisma\cli\build\index.js" generate
$> "PATH_TO_PROJECT\node_modules\@prisma\cli\build\index.js" generate
โ
Prisma Clients have been generated!
Hi @Dragons0458 ๐
After generating the Prisma Clients, does the prisma-multi-tenant new
command work ?
Hi @Errorname !
No, it gives me the same error :(
Did you run prisma-multi-tenant init
on your project ? After running prisma-multi-tenant generate
, is there a .prisma-multi-tenant/management
folder in your node_modules ?
That folder is not generated, I ran the init command and then the generate command and inside node_modules there is nothing :c
I just tried on a Windows machine, and I can reproduce! I will investigate and come back with a fix ๐
Thank you so much @Errorname ! successes! :D
The issue should be fixed with the prisma-multi-tenant@2.2.0-dev.6
release !
Since there is a lot of changes coming with the 2.2.0 release, I advise you to remove pmt from your project and globally, re-install it globally, and then running prisma-multi-tenant init
:
npm uninstall -g prisma-multi-tenant
npm uninstall prisma-multi-tenant
npm install -g prisma-multi-tenant
prisma-multi-tenant init
Let me know if it works for you ๐
Hello @Errorname ! sorry for the delay, this is the output I get:
$ prisma-multi-tenant init
Installing `@prisma-multi-tenant/client` as a dependency in your app...
We will now configure the management database:
? Management database url: file:management.db
? Are you sure of your inputs? Yes
Updating .env and schema.prisma files...
Generating prisma clients for both management and tenants...
Setting up management database...
Unknown Error!
{ Error: Command failed: node "PATH_TO_PROJECT\node_modules\@prisma\cli\build\index.js" migrate up --create-db --experimental
Error: Command failed with exit code 255: PATH_TO_PROJECT\node_modules\@prisma\cli\migration-engine-windows.exe cli --datasource file:PATH_TO_PROJECT\prisma\management.db create-database
Jul 22 18:26:47.307 INFO migration_engine: Starting migration engine CLI git_hash="e11114fa1ea826f9e7b4fa1ced34e78892fe8e0e"
Jul 22 18:26:47.308 ERROR migration_engine::commands: Unknown error occured: Error in datamodel: Error validating: This line is not a valid definition within a datasource.
{"is_panic":false,"message":"Unknown error occured: Error in datamodel: Error validating: This line is not a valid definition within a datasource.","backtrace":null}
at ChildProcess.exithandler (child_process.js:294:12)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
killed: false,
code: 1,
signal: null,
cmd:
'node "PATH_TO_PROJECT\\node_modules\\@prisma\\cli\\build\\index.js" migrate up --create-db --experimental' }
This is my package.json:
{
"name": "multi-tenant",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "npx ts-node index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@prisma/cli": "^2.3.0",
"@types/node": "^14.0.24",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"dependencies": {
"@prisma-multi-tenant/client": "^2.2.0-dev.6",
"@prisma/client": "^2.3.0"
}
}
And this is my .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://johndoe:randompassword@localhost:5432/mydb?schema=public"
DATABASE_URL=file:dev.db
# The following env variable is used by prisma-multi-tenant
MANAGEMENT_URL=file:management.db
Thank you very much for the help! :D
It looks like Prisma doesn't like something in your datasource in your schema.prisma file. Can you paste it here ?
Sure!
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Post {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
title String
content String?
published Boolean @default(false)
User User @relation(fields: [authorId], references: [id])
authorId Int
}
model Profile {
id Int @default(autoincrement()) @id
bio String?
User User @relation(fields: [userId], references: [id])
userId Int @unique
}
model User {
id Int @default(autoincrement()) @id
email String @unique
name String?
Post Post[]
Profile Profile?
}
Hmm, what happens when you do this command ?
npx prisma migrate up --experimental
This is the output:
npx prisma migrate up --experimental
Environment variables loaded from prisma\.env
โ You are trying to apply a migration for SQLite database dev.db.
A database with that name doesn't exist at file:dev.db
ยป Yes
migrate up
All migrations are already applied
And the files in my project folder:
I was able to reproduce again, and indeed Windows does some weird stuff sometimes ^^
I released prisma-multi-tenant@2.2.0-dev.7
, can you try installing it and retry?
Many times windows is quite an adventure, I hope Windows leaves wsl2 well soon :'v
Sorry @Errorname , I had this error, I cleared node_modules, did uninstall on global and local and reinstalled again. Itself I left it blank and I get this:
prisma-multi-tenant init
Installing `@prisma-multi-tenant/client` as a dependency in your app...
We will now configure the management database:
? Management database url: file:management.db
? Are you sure of your inputs? Yes
Updating .env and schema.prisma files...
Generating prisma clients for both management and tenants...
Setting up management database...
Unknown Error!
{ Error: Command failed: node "PATH_TO_PROJECT\node_modules\@prisma\cli\build\index.js" migrate up --create-db --experimental
Error: Command failed with exit code 255: PATH_TO_PROJECT\node_modules\@prisma\cli\migration-engine-windows.exe cli --datasource file:PATH_TO_PROJECT\prisma\management.db create-database
Jul 23 14:42:03.764 INFO migration_engine: Starting migration engine CLI git_hash="e11114fa1ea826f9e7b4fa1ced34e78892fe8e0e"
Jul 23 14:42:03.775 ERROR migration_engine::commands: Unknown error occured: Error in datamodel: Error validating: This line is not a valid definition within a datasource.
{"is_panic":false,"message":"Unknown error occured: Error in datamodel: Error validating: This line is not a valid definition within a datasource.","backtrace":null}
at ChildProcess.exithandler (child_process.js:294:12)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
killed: false,
code: 1,
signal: null,
cmd:
'node "PATH_TO_PROJECT\\node_modules\\@prisma\\cli\\build\\index.js" migrate up --create-db --experimental' }
Ah sorry, I made a typo while fixing the bug, this should now be fixed with prisma-multi-tenant@2.2.0-dev.8
๐ค
I already tried it and it works very well in Windows! thank you very much @Errorname ! :D You have done a great job with this package, congratulations!
I cannot initialize the prisma multi-tenant with the latest version. both init and new commands throw this error. I am using the beta.4
Error: Cannot find module '@prisma/prisma-multi-tenant/management'
I followed the get started step by step. no issues pre beta