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

Language tool support for named contraints/indexes #825

Closed
janpio opened this issue Jul 6, 2021 · 2 comments · Fixed by #919
Closed

Language tool support for named contraints/indexes #825

janpio opened this issue Jul 6, 2021 · 2 comments · Fixed by #919
Assignees
Labels
Milestone

Comments

@janpio
Copy link
Member

janpio commented Jul 6, 2021

In context of our #project-constraint-name-inclusion we will introduce some new attributes on block and field attributes. These will probably have to be added here to show up for auto completion:

"blockAttributes": [
{
"label": "@@map(\"\")",
"documentation": "Maps a model name from the Prisma schema to a different table name.",
"fullSignature": "@@map(_ name: String)",
"params": [
{
"label": "name",
"documentation": "The name of the target database table."
}
]
},
{
"label": "@@id([])",
"documentation": "Defines a multi-field ID on the model.",
"fullSignature": "@@id(_ fields: FieldReference[])",
"params": [
{
"label": "fields",
"documentation": "A list of references."
}
]
},
{
"label": "@@unique([])",
"documentation": "Defines a compound unique constraint for the specified fields.",
"fullSignature": "@@unique(_ fields: FieldReference[])",
"params": [
{
"label": "fields",
"documentation": "A list of references."
}
]
},
{
"label": "@@index([])",
"documentation": "Defines an index on the model.",
"fullSignature": "@@index(_ fields: FieldReference[])",
"params": [
{
"label": "fields",
"documentation": "A list of references."
}
]
},
{
"label": "@@ignore",
"documentation": "A model with an `@@ignore` attribute can be kept in sync with the database schema using Prisma Migrate and Introspection, but won't be exposed in Prisma Client.",
"fullSignature": "@@ignore",
"params": []
}
],
"fieldAttributes": [
{
"label": "@id",
"fullSignature": "@id",
"documentation": "Defines a single-field ID on the model.",
"params": []
},
{
"label": "@unique",
"fullSignature": "@unique",
"documentation": "Defines a unique constraint for this field.",
"params": []
},
{
"label": "@map(\"\")",
"documentation": "Maps a field name from the Prisma schema to a different column name.",
"fullSignature": "@map(_ name: String)",
"params": [
{
"label": "name",
"documentation": "The name of the target database column."
}
]
},
{
"label": "@default()",
"documentation": "Defines a default value for this field. `@default` takes an expression as an argument.",
"fullSignature": "@default(_ expression: Expression)",
"params": [
{
"label": "expression",
"documentation": "An expression (e.g. `5`, `true`, `now()`)."
}
]
},
{
"label": "@relation()",
"documentation": "Defines meta information about the relation. [Learn more](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#the-relation-attribute).",
"fullSignature": "@relation(_ name: String?, fields: FieldReference[]?, references: FieldReference[]?)",
"params": [
{
"label": "name",
"documentation": "Defines the name of the relationship. In an m-n-relation, it also determines the name of the underlying relation table."
},
{
"label": "fields",
"documentation": "A list of field references of the *current* model."
},
{
"label": "references",
"documentation": "A list of field references of the model on *the other side of the relation*."
},
{
"label": "onDelete",
"documentation": "Specifies the action to perform when a referenced entry in the referenced model is being deleted."
},
{
"label": "onUpdate",
"documentation": "Specifies the action to perform when a referenced field in the referenced model is being updated to a new value."
}
]
},

"relationArguments": [
{
"label": "references: []",
"fullSignature": "references: []",
"documentation": "A list of field references of the model on *the other side of the relation*.",
"params": []
},
{
"label": "fields: []",
"fullSignature": "fields: []",
"documentation": "A list of field references of the *current* model.",
"params": []
},
{
"label": "onDelete: ",
"fullSignature": "onDelete: ",
"documentation": "Specifies the action to perform when a referenced entry in the referenced model is being deleted.",
"params": []
},
{
"label": "onUpdate: ",
"fullSignature": "onUpdate: ",
"documentation": "Specifies the action to perform when a referenced field in the referenced model is being updated to a new value.",
"params": []
},
{
"label": "\"\"",
"fullSignature": "\"\"",
"documentation": "Defines the name of the relationship. In an m-n-relation, it also determines the name of the underlying relation table.",
"params": []
}
],

Affected:
@id, @@id, @@index, @unique, @@unique, @default, @relation

@janpio

This comment has been minimized.

@janpio janpio added this to the 2.31.0 / 3.0.x milestone Aug 19, 2021
@tomhoule tomhoule removed this from the 2.31.0 / 3.0.x milestone Sep 23, 2021
@tomhoule tomhoule added process/candidate Candidate for next Milestone. team/schema Issue for team Schema. labels Sep 23, 2021
@tomhoule tomhoule removed the process/candidate Candidate for next Milestone. label Oct 6, 2021
@tomhoule tomhoule added this to the 3.3.0 milestone Oct 6, 2021
@Jolg42 Jolg42 modified the milestones: 3.3.0, 3.4.0 Oct 25, 2021
@Jolg42 Jolg42 assigned Jolg42 and unassigned janpio Oct 25, 2021
@Jolg42
Copy link
Member

Jolg42 commented Oct 26, 2021

Note that this was shipped as GA with Prisma v3 https://github.com/prisma/prisma/releases/tag/3.0.1

First as a preview in https://github.com/prisma/prisma/releases/tag/2.29.0

Docs https://www.prisma.io/docs/concepts/components/prisma-schema/names-in-underlying-database

You can see that @id, @relation and @@unique now can take a map argument corresponding to the database name of the primary key/foreign key/constraint.

@@unique can also take a name argument to control the naming of the WhereUnique argument in Prisma Client.

A quick way to remember: The new API is uniform. map: "..." always corresponds to a name in the database, whereas name: "..." always corresponds to names in the Prisma Client API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants