Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator-helper: schema attribute is not exposed to generators when using multiSchema #19987

Open
duniul opened this issue Jun 27, 2023 · 0 comments
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. team/schema Issue for team Schema. topic: dmmf topic: generator topic: multiSchema multiple schemas

Comments

@duniul
Copy link

duniul commented Jun 27, 2023

This was also reported in the feature feedback thread, but I thought it could be worth tracking separately.

Bug description

@prisma/generator-helper does not expose any information about a model's schema, preventing generators like https://github.com/notiz-dev/prisma-dbml-generator or https://github.com/valtyr/prisma-kysely to generate proper table names without workarounds.

It's missing from both the type (DMMF.Model) and the model objects provided to generatorHandler's onGenerate function (options.dmmf.datamodel.models).

How to reproduce

  1. Create a simple generator with @prisma/generator-helper and log the output.
    import { GeneratorOptions, generatorHandler } from "@prisma/generator-helper";
    
    generatorHandler({
      onGenerate: async (options: GeneratorOptions) => {
        console.log(options.dmmf.datamodel.models);
      },
    });
  2. Add a prisma/schema.prisma file with multiSchema enabled that uses the generator.
  3. Run prisma generate and look at the log - models do not include any schema info.

Expected behavior

That a model's schema is included on the DMMF.Model object, e.g. like:

interface Model {
    name: string;
    dbName: string | null;
    schema: string | null; // <-- e.g. like this
    fields: Field[];
    uniqueFields: string[][];
    uniqueIndexes: uniqueIndex[];
    documentation?: string;
    primaryKey: PrimaryKey | null;
    [key: string]: any;
}

Prisma information

Example Prisma schema:

generator client {
    provider        = "prisma-client-js"
    previewFeatures = ["multiSchema"]
}

datasource db {
    provider = "postgresql"
    schemas  = ["mammals", "birds"]
    url      = env("DATABASE_URL")
}

model Dog {
    id   Int    @id
    name String

    @@schema("mammals")
}

model Parrot {
    id   Int    @id
    name String

    @@schema("birds")
}

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v18.15.0

Prisma Version

prisma                  : 4.16.1
@prisma/client          : Not found
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine b20ead4d3ab9e78ac112966e242ded703f4a052c (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli b20ead4d3ab9e78ac112966e242ded703f4a052c (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c
Default Engines Hash    : b20ead4d3ab9e78ac112966e242ded703f4a052c
Studio                  : 0.484.0
Preview Features        : multiSchema
@duniul duniul added the kind/bug A reported bug. label Jun 27, 2023
@jkomyno jkomyno added kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: multiSchema multiple schemas team/client Issue for team Client. and removed kind/bug A reported bug. labels Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. team/schema Issue for team Schema. topic: dmmf topic: generator topic: multiSchema multiple schemas
Projects
None yet
Development

No branches or pull requests

3 participants