Giter VIP home page Giter VIP logo

prisma-import's People

Contributors

ajmnz avatar daniellehuisman avatar dependabot[bot] avatar github-actions[bot] avatar hunterlarco avatar jared-fraser avatar nawilson avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

prisma-import's Issues

Merging Models

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
image

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

Completion for native types lost

@db.* keywords have lost completion suggestions. Probably due to the datasource not being in scope, which should be an easy fix.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Use matchDepNames instead of matchPackageNames

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @types/node to v20
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-plugin-unused-imports to v4
  • chore(deps): update dependency execa to v9
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency lint-staged to v15
  • chore(deps): update dependency p-retry to v6
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency release-it to v17
  • chore(deps): update peter-evans/create-pull-request action to v6
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • fix(deps): update dependency @prisma/internals to v5
  • fix(deps): update dependency glob to v10
  • fix(deps): update dependency minimatch to v9
  • fix(deps): update dependency read-pkg-up to v11
  • fix(deps): update dependency vscode-languageclient to v9
  • fix(deps): update dependency vscode-languageserver to v9
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.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
npm
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

  • Check this box to trigger a request for Renovate to run again on this repository

Native database type attributes raise errors in VS Code extension

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"
     }
}

Package.json format

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?

Command for merging in VSCode

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.
image

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

Necessary parts of the root schema are overwritten.

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?

Improve docs

Docs were written when this was just an experiment and would probably benefit from a rewrite with clearer instructions

npx prisma-multischema error

i running npx prisma-multischema and then result error
env: node\r: No such file or directory

whereas i running node -v is show
image

Unexpected error on main file which defines datasource

1

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.

Formatting one file dirties another file unecessarily

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"
  }
}

Using 1.0.4 - Appends to file rather than truncating...

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!

One error in imports makes everything invalid

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

Unable to run on linux

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?

updating prisma to 5.11 and using the experimental flag is showing a type error

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

Semantic support request: `import * from ..`

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 ๐Ÿ˜‚

(feature/bug) Using native db types in nested models

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.