ajmnz / prisma-import Goto Github PK
View Code? Open in Web Editor NEWBringing import statements to Prisma schemas
Bringing import statements to Prisma schemas
Hi there,
I am trying out prisma-import as a replacement for Aurora. I am not sure what I am doing wrong.
base.prisma
import {Person} from "./Person"
datasource db {
provider = "mysql"
url = env("GPerson-DATABASE_URL")
relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
output = env("GPerson-Prisma_Client_Dir")
}
model Person {
id String @id
password String? /// This is defined here because I dont want it in other schemas that import Person
}
Person.prisma
model Person {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
first_name String
last_name String
}
I get the following errors in base.prisma
When I run prisma-import on base.prisma I get the following:
//
// Autogenerated by `prisma-import`
// Any modifications will be overwritten on subsequent runs.
//
//
// base.prisma
//
datasource db {
provider = "mysql"
url = env("GPerson-DATABASE_URL")
relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
output = env("GPerson-Prisma_Client_Dir")
}
model Person {
id String @id
password String? /// This is defined here because I dont want it in other schemas that import Person
}
So 2 things, why the errors in VSCode about multiple db's and why arn't the fields like first_name from Person.prisma showing up in the merged Person model?
Thanks
It would be great to create jetbrains extension
@db.*
keywords have lost completion suggestions. Probably due to the datasource
not being in scope, which should be an easy fix.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These problems occurred while renovating this repository. View logs.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@types/mocha
, @types/prompts
)@types/js-levenshtein
, checkpoint-client
, glob
, minimatch
, vscode-languageserver
, vscode-languageserver-textdocument
)@vscode/test-electron
, @vscode/vsce
, eslint
, mocha
, ovsx
, semver
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/1_check_for_updates.yml
actions/checkout v3
actions/setup-node v3
benc-uk/workflow-dispatch v1
.github/workflows/2_bump_versions.yml
actions/checkout v3
actions/setup-node v3
benc-uk/workflow-dispatch v1
.github/workflows/3_LS_tests_publish.yml
actions/checkout v3
actions/setup-node v3
actions/checkout v3
actions/setup-node v3
benc-uk/workflow-dispatch v1
.github/workflows/4_bump_LS_in_extension.yml
actions/checkout v3
actions/setup-node v3
benc-uk/workflow-dispatch v1
.github/workflows/5_e2e_tests.yml
actions/checkout v3
actions/setup-node v3
GabrielBB/xvfb-action v1.6
actions/checkout v3
actions/setup-node v3
benc-uk/workflow-dispatch v1
.github/workflows/6_build_publish.yml
actions/checkout v3
actions/setup-node v3
.github/workflows/check_commits.yml
actions/checkout v3
actions/setup-node v3
actions/checkout v3
peter-evans/create-pull-request v4
.github/workflows/ci.yml
actions/checkout v3
actions/setup-node v3
GabrielBB/xvfb-action v1.6
package.json
@typescript-eslint/eslint-plugin 5.62.0
@typescript-eslint/parser 5.62.0
eslint 8.51.0
eslint-config-prettier 8.10.0
eslint-plugin-prettier 4.2.1
eslint-plugin-unused-imports 2.0.0
husky 8.0.3
lint-staged 13.3.0
pinst >=2
prettier 2.8.8
execa 5.1.1
p-retry 4.6.2
semver 7.5.4
packages/language-server/package.json
@types/js-levenshtein 1.1.1
js-levenshtein 1.1.6
klona 2.0.6
nyc 15.1.0
vscode-languageserver 8.0.2
vscode-languageserver-textdocument 1.0.7
@types/mocha 10.0.2
@types/node 14.18.63
mocha 10.2.0
release-it 15.11.0
rimraf 3.0.2
ts-dedent 2.2.0
typescript 4.9.5
node >=14
packages/prisma-import/package.json
@prisma/internals 4.16.2
chalk 4.1.2
glob 8.0.3
prompts 2.4.2
read-pkg-up 9.1.0
@types/node 17.0.45
@types/glob 8.1.0
@types/prompts 2.4.6
release-it 15.11.0
typescript 4.9.5
packages/vscode/package.json
@ajmnz/prisma-language-server 5.12.1
checkpoint-client 1.1.23
minimatch 6.0.0
vscode-languageclient 7.0.0
watcher ^1.2.0
@types/glob 8.1.0
@types/mocha 10.0.2
@types/vscode 1.56.0
@vscode/test-electron 2.3.9
@vscode/vsce 2.21.1
is-ci 3.0.1
mocha 10.2.0
ovsx 0.8.3
release-it 15.11.0
rimraf 3.0.2
typescript 4.9.5
vscode ^1.56.0
I'm using Prisma Import CLI and the VS Code extension and love it so far, but I ran into a minor issue. I'm trying to use the @db.Uuid
attribute for a PostgreSQL database, so it uses the native uuid
type. Unfortunately, the VS Code extension raises the following error:
Native type Uuid is not supported for sqlite connector.
Is there any way I can specify the datasource provider in the extension? For the CLI part I have a base.prisma
schema, so it works fine in the generated schema, but it would be even better if the extension didn't show errors for these attributes.
Relevant files
prisma/base.prisma
:
generator client {
provider = "prisma-client-js"
previewFeatures = ["jsonProtocol"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("DATABASE_SHADOW_URL")
}
src/models/User.prisma
:
model User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
}
package.json
{
"scripts": {
"prisma": "prisma-import -f -s '{prisma/base.prisma,src/**/*.prisma}' -o prisma/schema.prisma && prisma"
}
}
Probably related to trimming the file on format after identifying where the virtual schema starts.
Hey! I've been trying to set up prisma-import
on a new project using package.json
settings. I tried the following settings:
{
"prisma": {
"import": {
"schemas": [
"schema/config.prisma",
"schema/models/**/*.prisma"
],
"output": "schema/schema.prisma"
}
}
}
But when I run npx prima-import
I get the following error:
/Users/sebastian/.npm/_npx/56402732312c327d/node_modules/minimatch/minimatch.js:125
throw new TypeError('invalid pattern')
^
TypeError: invalid pattern
at assertValidPattern (/Users/sebastian/.npm/_npx/56402732312c327d/node_modules/minimatch/minimatch.js:125:11)
at new Minimatch (/Users/sebastian/.npm/_npx/56402732312c327d/node_modules/minimatch/minimatch.js:166:5)
at setopts (/Users/sebastian/.npm/_npx/56402732312c327d/node_modules/glob/common.js:118:20)
at new Glob (/Users/sebastian/.npm/_npx/56402732312c327d/node_modules/glob/glob.js:132:3)
at glob (/Users/sebastian/.npm/_npx/56402732312c327d/node_modules/glob/glob.js:72:10)
at node:internal/util:442:7
at new Promise (<anonymous>)
at glob (node:internal/util:428:12)
at /Users/sebastian/.npm/_npx/56402732312c327d/node_modules/prisma-import/dist/index.js:68:38
at Generator.next (<anonymous>)
My guess is prisms.import.schemas
cannot be a list? Is this a bug or intended?
Hello, I'm trying out with your extension. In description at marketplace there two ways of merging schemas into one and I pick with the running command in VSCode, but apparently there no such command for merging.
For Prisma
is available only three commands.
The official extension were removed and restarted app few times.
To be mentioned, I'm using Windows 10, but not sure that this causes the problem
I might be misunderstanding this, but this package has a major issue. A prisma schema always needs to have these additions:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
But when i run the CLI this will always be overwritten... So what's the point even? The intellisense and importing is amazing but if this breaks it, its quite useless to me. What am i missing here?
Docs were written when this was just an experiment and would probably benefit from a rewrite with clearer instructions
I have two schemas:
schema.prisma
import { Dep } from "./module.schema"
module.schema.prisma
...
When I drag module.schema.prisma
to a new directory, say schemas
, it does not update schema.prisma
's link, which should become:
import { Dep } from "./schemas/module.schema"
Any ideas on how to implement this, or where to look to get started? Would be happy to help contribute.
All my models in separate folder while my main prisma file which defines datasource in separate sibling directory. When I open main file extension shows such error.
Error validating datasource `db`: You defined more than one datasource. This is not allowed yet because support for multiple databases has not been implemented yet.
I have two prisma files
1. Company.prisma
import { CompanyDetails } from "../CompanyDetails/CompanyDetails"
model Company {
id String @id
name String
slug String @unique
details CompanyDetails?
}
2. CompanyDetails.prisma
import { Company } from "../Company/Company"
model CompanyDetails {
companyId String @id
shortBio String
company Company @relation(fields: [companyId], references: [id])
}
When I manually format CompanySchema.prisma
, it leaves 1 blank newline at the end of the file, but then it automatically formats CompanyDetailsSchema.prisma
with 2 blank newlines at the end of file. Same thing happens when I go to manually format CompanyDetailsSchema.prisma
. So I format one file, it dirties the other. Then I format the other file and it dirties the original. Ad infinitum.
My vscode settings.json
:
{
"[prisma]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ajmnz.prisma-import"
}
}
This is a great project, so let me thank you again for taking the time to develop it! ๐
With the following prompt:
โ This will overwrite your output schema. You can disable this prompt with the --force option. Continue?
I was expecting that the file would be truncated and then appended to.
Unfortunately, I'm not seeing the truncate, only an append. So everything is duplicated.
Hopefully this isn't just me and you can replicate?
Many thanks!
When there's an error within imports (ie model not found), we skip generating the virtual schema and thus all other imports are invalid resulting in a bunch of errors.
Find if it is safe to create a virtual schema knowing there are errors
I'm using Ubuntu 22.04, when trying to run prisma-import --schemas ./prisma/schemas/*.prisma --output ./prisma/schema.prisma
I'm hit with
Error: Provide an output path. Either pass it with --output or add it to your package.json at prisma.import.output
But the same command above works perfectly fine when running it on windows. Am I doing something wrong?
generator client {
provider = "prisma-client-js"
previewFeatures = ["relationJoins"]
}
gives me the following type error The preview feature "relationJoins" is not known. Expected one of: fullTextSearch, fullTextIndex, tracing, metrics, multiSchema, fieldReference, postgresqlExtensions, deno, extendedWhereUnique, views, jsonProtocol
Awesome project, btw, @ajmnz
Would be nice to split schemas up into remote parts, one thing I've always resented about prisma is the (potentially) thousands of lines long model files. It would be awesome to have a system where I could do smoething like:
...
import * from "./path/to/model1.schema"
import * from "./path/to/model2.schema"
import * from "./path/to/model3.schema"
...
Again, would be happy to contribute to something like this. I don't love that the prisma
team has taken the stance that the community is responsible for implementing this kind of functionality, but you're the first project that is offering this stuff so let's just roll with it ๐
Hello! First of all I would like to say that this plugin could be really handy, thanks for it!
Looks like currently it is not possible to use native db types in nested models without getting error in vscode.
That is because for example native type @db.Uuid in some nested file should refer to db datasource section, which is in root schema.prisma file so without importing it in nested file is an error in vscode ("Native type Uuid is not supported for Default connector."), but after importing it the error in root schema.prisma the other error shows up because plugin thinks that db datasource was defined twice ("You defined more than one datasource").
Also regrading cli command - looks like there is no need to use glob pattern to include all schemas, if the imports are strictly declared and have a relative paths the paths to nested schemas could be resolved from parent schema path. As for now looks like it does not matter wether the nested file was imported or not it would anyway be merged based on glob pattern.
UPD: One more thing spotted, if there is already merged schema in the scope of glob pattern then this schema also would be included in the result one (with force flag enabled). Looks like the force flag should delete the previous result by the output file path or exclude it from the result of the search by glob pattern.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.