From ef33fa4645aa08509c61c428007cabdeaebe30ff Mon Sep 17 00:00:00 2001 From: Errorname Date: Tue, 26 May 2020 15:27:50 +0200 Subject: [PATCH] :bookmark: Release 2.0.0-beta.6 --- README.md | 2 +- docs/examples/basic-js/package-lock.json | 18 ++++++------- docs/examples/basic-js/package.json | 6 ++--- docs/examples/basic-ts/package-lock.json | 18 ++++++------- docs/examples/basic-ts/package.json | 6 ++--- package-lock.json | 8 +++--- package.json | 6 ++--- src/cli/commands/init.ts | 6 ++--- .../README.md | 27 ++++++++++--------- .../schema.prisma | 5 ++-- .../steps.json | 0 src/cli/prisma/migrations/migrate.lock | 5 +--- src/cli/prisma/schema.prisma | 5 ++-- src/shared/env.ts | 2 +- src/shared/management.ts | 2 +- src/shared/shell.ts | 6 ++++- tests/playground/example/package.json | 4 +-- 17 files changed, 65 insertions(+), 61 deletions(-) rename src/cli/prisma/migrations/{20200411135513-alpha => 20200526145455-beta}/README.md (54%) rename src/cli/prisma/migrations/{20200411135513-alpha => 20200526145455-beta}/schema.prisma (66%) rename src/cli/prisma/migrations/{20200411135513-alpha => 20200526145455-beta}/steps.json (100%) diff --git a/README.md b/README.md index 3a04bfb..23305ff 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ npm i -g prisma-multi-tenant@beta ``` $> prisma-multi-tenant help - 🧭 prisma-multi-tenant v2.0.0-beta.5 + 🧭 prisma-multi-tenant v2.0.0-beta.6 USAGE diff --git a/docs/examples/basic-js/package-lock.json b/docs/examples/basic-js/package-lock.json index 5ac1951..dd6afde 100644 --- a/docs/examples/basic-js/package-lock.json +++ b/docs/examples/basic-js/package-lock.json @@ -5,15 +5,15 @@ "requires": true, "dependencies": { "@prisma/cli": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.5.tgz", - "integrity": "sha512-Kl3IqOq6sYdajnLA034SLJxFCB0IxXcrSLYR8W9XTOyt3RRP/TCUPp5yBVfO9B21Kwe9YrFujTbSD2qQaDg1QA==", + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.6.tgz", + "integrity": "sha512-qawcjLN5c26T+IVZij5WjQocfsV6b1BtJIL3CqMQfMkDCNGo/zXsu+NB+uyZ+QRqctEuJQ36lemnY44+k6L8XA==", "dev": true }, "@prisma/client": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.5.tgz", - "integrity": "sha512-Ov7rOV5h+nu+zSFG61OvOTsDjQX+QSa8AI0sYbNSsfL9MvEMtb7mMCiGsQRdHGvxbqErFuqlN83+eUCR/umb1Q==" + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.6.tgz", + "integrity": "sha512-08AokCpMzL6SdxQVfShD7937t+sHntr6FJBpVKq5E/UFPVh0B2lUwU9YrA/MIAdRpGMg1wA+rdwRivtFIs5Law==" }, "@types/color-name": { "version": "1.1.1", @@ -963,9 +963,9 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, "prisma-multi-tenant": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.5.tgz", - "integrity": "sha512-VK64DjmQaBP5Pdz8PGqJ/tnJX/bi44NSVPD0EA+SdROESmU9MxlpNAwV2YNqn5vcWcUewPO5hg6hMoq3TtUfag==", + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.6.tgz", + "integrity": "sha512-juG6R0vla8uaaGktd0Xbubera2U+jGOBWPcW5aKvuVaw53kbd2nPjEc04aSTFP554ZWH0spL94WFAWJNYG7T+A==", "requires": { "arg": "^4.1.2", "chalk": "^3.0.0", diff --git a/docs/examples/basic-js/package.json b/docs/examples/basic-js/package.json index 0de54df..e3afd6f 100644 --- a/docs/examples/basic-js/package.json +++ b/docs/examples/basic-js/package.json @@ -10,10 +10,10 @@ "author": "", "license": "ISC", "devDependencies": { - "@prisma/cli": "2.0.0-beta.5" + "@prisma/cli": "2.0.0-beta.6" }, "dependencies": { - "@prisma/client": "2.0.0-beta.5", - "prisma-multi-tenant": "2.0.0-beta.5" + "@prisma/client": "2.0.0-beta.6", + "prisma-multi-tenant": "2.0.0-beta.6" } } diff --git a/docs/examples/basic-ts/package-lock.json b/docs/examples/basic-ts/package-lock.json index e8f00dc..63dfa4b 100644 --- a/docs/examples/basic-ts/package-lock.json +++ b/docs/examples/basic-ts/package-lock.json @@ -5,15 +5,15 @@ "requires": true, "dependencies": { "@prisma/cli": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.5.tgz", - "integrity": "sha512-Kl3IqOq6sYdajnLA034SLJxFCB0IxXcrSLYR8W9XTOyt3RRP/TCUPp5yBVfO9B21Kwe9YrFujTbSD2qQaDg1QA==", + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.6.tgz", + "integrity": "sha512-qawcjLN5c26T+IVZij5WjQocfsV6b1BtJIL3CqMQfMkDCNGo/zXsu+NB+uyZ+QRqctEuJQ36lemnY44+k6L8XA==", "dev": true }, "@prisma/client": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.5.tgz", - "integrity": "sha512-Ov7rOV5h+nu+zSFG61OvOTsDjQX+QSa8AI0sYbNSsfL9MvEMtb7mMCiGsQRdHGvxbqErFuqlN83+eUCR/umb1Q==" + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.6.tgz", + "integrity": "sha512-08AokCpMzL6SdxQVfShD7937t+sHntr6FJBpVKq5E/UFPVh0B2lUwU9YrA/MIAdRpGMg1wA+rdwRivtFIs5Law==" }, "@types/color-name": { "version": "1.1.1", @@ -978,9 +978,9 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, "prisma-multi-tenant": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.5.tgz", - "integrity": "sha512-VK64DjmQaBP5Pdz8PGqJ/tnJX/bi44NSVPD0EA+SdROESmU9MxlpNAwV2YNqn5vcWcUewPO5hg6hMoq3TtUfag==", + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.6.tgz", + "integrity": "sha512-juG6R0vla8uaaGktd0Xbubera2U+jGOBWPcW5aKvuVaw53kbd2nPjEc04aSTFP554ZWH0spL94WFAWJNYG7T+A==", "requires": { "arg": "^4.1.2", "chalk": "^3.0.0", diff --git a/docs/examples/basic-ts/package.json b/docs/examples/basic-ts/package.json index 16db016..a1c10b0 100644 --- a/docs/examples/basic-ts/package.json +++ b/docs/examples/basic-ts/package.json @@ -10,11 +10,11 @@ "author": "", "license": "ISC", "devDependencies": { - "@prisma/cli": "2.0.0-beta.5" + "@prisma/cli": "2.0.0-beta.6" }, "dependencies": { - "@prisma/client": "2.0.0-beta.5", - "prisma-multi-tenant": "2.0.0-beta.5", + "@prisma/client": "2.0.0-beta.6", + "prisma-multi-tenant": "2.0.0-beta.6", "ts-node": "8.6.2", "typescript": "3.8.2" } diff --git a/package-lock.json b/package-lock.json index 34e932e..5c8082c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prisma-multi-tenant", - "version": "2.0.0-beta.5", + "version": "2.0.0-beta.6", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1450,9 +1450,9 @@ } }, "@prisma/cli": { - "version": "2.0.0-beta.5", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.5.tgz", - "integrity": "sha512-Kl3IqOq6sYdajnLA034SLJxFCB0IxXcrSLYR8W9XTOyt3RRP/TCUPp5yBVfO9B21Kwe9YrFujTbSD2qQaDg1QA==", + "version": "2.0.0-beta.6", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.6.tgz", + "integrity": "sha512-qawcjLN5c26T+IVZij5WjQocfsV6b1BtJIL3CqMQfMkDCNGo/zXsu+NB+uyZ+QRqctEuJQ36lemnY44+k6L8XA==", "dev": true }, "@sinonjs/commons": { diff --git a/package.json b/package.json index 0640571..c77956c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prisma-multi-tenant", - "version": "2.0.0-beta.5", + "version": "2.0.0-beta.6", "description": "🧭 Use Prisma as a multi-tenant provider for your application", "author": { "name": "Thibaud Courtoison", @@ -34,13 +34,13 @@ "inquirer": "^7.0.4" }, "peerDependencies": { - "@prisma/cli": "^2.0.0-beta.5" + "@prisma/cli": "^2.0.0-beta.6" }, "devDependencies": { "@babel/core": "^7.8.3", "@babel/preset-env": "^7.8.3", "@babel/preset-typescript": "^7.8.3", - "@prisma/cli": "^2.0.0-beta.5", + "@prisma/cli": "^2.0.0-beta.6", "@types/inquirer": "^6.5.0", "@types/jest": "^25.1.0", "@types/node": "^13.7.0", diff --git a/src/cli/commands/init.ts b/src/cli/commands/init.ts index 2b0a660..4d792b6 100644 --- a/src/cli/commands/init.ts +++ b/src/cli/commands/init.ts @@ -145,11 +145,9 @@ class Init implements Command { async createExample(firstTenant: Tenant | null) { console.log('\n Creating example script...') - const { PrismaClient } = requireDistant('@prisma/client') + const { dmmf } = requireDistant('@prisma/client') - const tenant = new PrismaClient() - - const firstModelMapping = tenant.dmmf.mappings[0] + const firstModelMapping = dmmf.mappings[0] // We should use singular name (See prisma/prisma-client-js#509) const modelNamePlural = firstModelMapping.plural diff --git a/src/cli/prisma/migrations/20200411135513-alpha/README.md b/src/cli/prisma/migrations/20200526145455-beta/README.md similarity index 54% rename from src/cli/prisma/migrations/20200411135513-alpha/README.md rename to src/cli/prisma/migrations/20200526145455-beta/README.md index a037061..a1bb6fa 100644 --- a/src/cli/prisma/migrations/20200411135513-alpha/README.md +++ b/src/cli/prisma/migrations/20200526145455-beta/README.md @@ -1,38 +1,41 @@ -# Migration `20200411135513-alpha` +# Migration `20200526145455-beta` -This migration has been generated by Errorname at 4/11/2020, 1:55:13 PM. +This migration has been generated by Errorname at 5/26/2020, 2:54:55 PM. You can check out the [state of the schema](./schema.prisma) after the migration. ## Database Steps ```sql +PRAGMA foreign_keys=OFF; + CREATE TABLE "quaint"."Tenant" ( - "id" TEXT NOT NULL , - "name" TEXT NOT NULL , - "provider" TEXT NOT NULL , - "url" TEXT NOT NULL , - PRIMARY KEY ("id") -) +"id" TEXT NOT NULL ,"name" TEXT NOT NULL ,"provider" TEXT NOT NULL ,"url" TEXT NOT NULL , + PRIMARY KEY ("id")) CREATE UNIQUE INDEX "quaint"."Tenant.name" ON "Tenant"("name") + +PRAGMA "quaint".foreign_key_check; + +PRAGMA foreign_keys=ON; ``` ## Changes ```diff diff --git schema.prisma schema.prisma -migration ..20200411135513-alpha +migration ..20200526145455-beta --- datamodel.dml +++ datamodel.dml -@@ -1,0 +1,16 @@ +@@ -1,0 +1,17 @@ +datasource management { + provider = "sqlite" + url = env("PMT_MANAGEMENT_URL") +} + +generator client { -+ provider = "prisma-client-js" -+ output = env("PMT_OUTPUT") ++ provider = "prisma-client-js" ++ output = env("PMT_OUTPUT") ++ binaryTargets = ["native"] +} + +model Tenant { diff --git a/src/cli/prisma/migrations/20200411135513-alpha/schema.prisma b/src/cli/prisma/migrations/20200526145455-beta/schema.prisma similarity index 66% rename from src/cli/prisma/migrations/20200411135513-alpha/schema.prisma rename to src/cli/prisma/migrations/20200526145455-beta/schema.prisma index 4b36e38..151b2ed 100644 --- a/src/cli/prisma/migrations/20200411135513-alpha/schema.prisma +++ b/src/cli/prisma/migrations/20200526145455-beta/schema.prisma @@ -4,8 +4,9 @@ datasource management { } generator client { - provider = "prisma-client-js" - output = env("PMT_OUTPUT") + provider = "prisma-client-js" + output = env("PMT_OUTPUT") + binaryTargets = ["native"] } model Tenant { diff --git a/src/cli/prisma/migrations/20200411135513-alpha/steps.json b/src/cli/prisma/migrations/20200526145455-beta/steps.json similarity index 100% rename from src/cli/prisma/migrations/20200411135513-alpha/steps.json rename to src/cli/prisma/migrations/20200526145455-beta/steps.json diff --git a/src/cli/prisma/migrations/migrate.lock b/src/cli/prisma/migrations/migrate.lock index a3f890b..17f5b7b 100644 --- a/src/cli/prisma/migrations/migrate.lock +++ b/src/cli/prisma/migrations/migrate.lock @@ -1,6 +1,3 @@ -# IF THERE'S A GIT CONFLICT IN THIS FILE, DON'T SOLVE IT MANUALLY! -# INSTEAD EXECUTE `prisma migrate fix` # Prisma Migrate lockfile v1 -# Read more about conflict resolution here: TODO -20200411135513-alpha \ No newline at end of file +20200526145455-beta \ No newline at end of file diff --git a/src/cli/prisma/schema.prisma b/src/cli/prisma/schema.prisma index 1610e2b..5eda1a7 100644 --- a/src/cli/prisma/schema.prisma +++ b/src/cli/prisma/schema.prisma @@ -4,8 +4,9 @@ datasource management { } generator client { - provider = "prisma-client-js" - output = env("PMT_OUTPUT") + provider = "prisma-client-js" + output = env("PMT_OUTPUT") + binaryTargets = ["native"] } model Tenant { diff --git a/src/shared/env.ts b/src/shared/env.ts index b6b4e53..62c02f2 100644 --- a/src/shared/env.ts +++ b/src/shared/env.ts @@ -87,7 +87,7 @@ export const setManagementProviderInMigration = async (): Promise => { // 1. Find migration steps file const stepsPath = path.join( nodeModules, - 'prisma-multi-tenant/build/cli/prisma/migrations/20200411135513-alpha/steps.json' + 'prisma-multi-tenant/build/cli/prisma/migrations/20200526145455-beta/steps.json' ) if (!(await fileExists(stepsPath))) { diff --git a/src/shared/management.ts b/src/shared/management.ts index 6177acc..ca4b55b 100644 --- a/src/shared/management.ts +++ b/src/shared/management.ts @@ -26,7 +26,7 @@ export default class Management { PrismaClient = requireDistant(clientManagementPath).PrismaClient } catch { console.error( - `\nError: Cannot find module '@prisma/prisma-multi-tenant/management'.\n\nTry running "prisma-multi-tenant generate"\n` + `\nError: Cannot find module '.prisma-multi-tenant/management'.\n\nTry running "prisma-multi-tenant generate"\n` ) process.exit(1) } diff --git a/src/shared/shell.ts b/src/shared/shell.ts index a75750a..d808675 100644 --- a/src/shared/shell.ts +++ b/src/shared/shell.ts @@ -145,7 +145,9 @@ export const writeFile = (path: string, content: string): Promise => { } export const requireDistant = (name: string): any => { - return require(require.resolve(name, { + // Keep previous env so that the required module doesn't update it + const previousEnv = { ...process.env } + const required = require(require.resolve(name, { paths: [ process.cwd() + '/node_modules/', process.cwd(), @@ -153,6 +155,8 @@ export const requireDistant = (name: string): any => { __dirname + '/../../../' ] })) + process.env = previousEnv + return required } export const useYarn = (): Promise => { diff --git a/tests/playground/example/package.json b/tests/playground/example/package.json index a8e047f..f1afc44 100644 --- a/tests/playground/example/package.json +++ b/tests/playground/example/package.json @@ -3,10 +3,10 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@prisma/client": "2.0.0-beta.5" + "@prisma/client": "2.0.0-beta.6" }, "devDependencies": { - "@prisma/cli": "2.0.0-beta.5" + "@prisma/cli": "2.0.0-beta.6" }, "scripts": { "dev": "node ./script.js"