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

DRAFT: Support compound primary key ids in SDL and Scaffold generators #6051

Closed

Conversation

dthyresson
Copy link
Contributor

First step to address #5689

As @joconor notes:

Prisma model:

model Xpolicy {
  enterprise String
  name       String

  @@id([enterprise, name])
}

yarn rw prisma migrate dev runs successfully
yarn rw g scaffold xpolicy results in error:


  ┌─────────────────────────────────────────────────────────────────────────┐
  │                                                                         │
  │   WARNING: Cannot generate CRUD SDL without an `@id` database column.   │
  │                                                                         │
  │   If you are trying to generate for a many-to-many join table           │
  │   you'll need to update your schema definition to include               │
  │   an `@id` column. Read more here:                                      │
  │   https://redwoodjs.com/docs/schema-relations                           │
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘



  ✖ Generating scaffold files...
    → Failed: Could not generate SDL
    Adding layout import...
    Adding set import...
    Adding scaffold routes...
    Adding scaffold asset imports...
    Generating types ...
Failed: Could not generate SDL

Shouldn't this be as simple as using the Prisma generated composite ID field for the SDL? See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#id-1

This PR instead of iterastingthe fields to check if is an id, uses the the Model's primaryKey property instead.

https://github.com/prisma/prisma/blob/da4538d42aca8d7ab2777a979c0e8293f78b22b9/packages/generator-helper/src/dmmf.ts#L61

export interface Model {
    name: string
    dbName: string | null
    fields: Field[]
    fieldMap?: Record<string, Field>
    uniqueFields: string[][]
    uniqueIndexes: uniqueIndex[]
    documentation?: string
    primaryKey: PrimaryKey | null
    [key: string]: any // safe net for additional new props // TODO: remove this and the others, not safe
  }

And since PrimaryKey also has a name

  export interface PrimaryKey {
    name: string | null
    fields: string[]
  }

However, this just addresses the SDL.

Tasks:

  • Handle compound id in SDL
  • Service and test and scenarios
  • replace use of id in template but a way to get the name of the id
  • Change up all scaffold pages and forms and cell queries to use the field id name instead of just hardcoded id

@nx-cloud
Copy link

nx-cloud bot commented Jul 26, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 141210c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 14 targets

Sent with 💌 from NxCloud.

@netlify
Copy link

netlify bot commented Jul 26, 2022

Deploy Preview for redwoodjs-docs ready!

Name Link
🔨 Latest commit 141210c
🔍 Latest deploy log https://app.netlify.com/sites/redwoodjs-docs/deploys/62e020cd2868090009705a3d
😎 Deploy Preview https://deploy-preview-6051--redwoodjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@dthyresson dthyresson added the release:feature This PR introduces a new feature label Jul 26, 2022
@dthyresson dthyresson changed the title DRAFT: Support compound primary key ids in SDL generation. DRAFT: Support compound primary key ids in SDL and Scaffold generators Jul 26, 2022
@dthyresson
Copy link
Contributor Author

Due to the extent of the template rework, the team decided to hold off on this issue until the template engine is updated.

Moved to Backlog.

@dthyresson dthyresson removed their assignment Aug 1, 2022
@dthyresson dthyresson added the p3 Low priority. The Core team will not prioritize this for now label Dec 13, 2023
@Tobbe
Copy link
Member

Tobbe commented Dec 18, 2023

Cross-linking this one to #8556

@Tobbe
Copy link
Member

Tobbe commented Dec 19, 2023

Closing in favor of the linked PR

@Tobbe Tobbe closed this Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 Low priority. The Core team will not prioritize this for now release:feature This PR introduces a new feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants