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

fix(names-in-underlying-database): Iterate on structure #2268

Closed
wants to merge 37 commits into from

Conversation

janpio
Copy link
Contributor

@janpio janpio commented Sep 3, 2021

The page is certainly fine, but somehow felt backwards in many ways.
This is my (WIP) attempt to simplify and restructure all these things so the topic gets a page that really helps our users to understand the feature.

molebox and others added 30 commits August 20, 2021 11:44
* working on tutorial

* MSSQL tasks, 2095, 2083, 2094, 2091, 2086, 2082

* working on tutorial

* MSSQL tasks, 2095, 2083, 2094, 2091, 2086, 2082

* Update content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx

Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>

* Feedback changes, including: mssql => sqlserver, clean up sections, fix sql tables

Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
* Updated query raw page

* Made sql injection warning scary

* Changed sql injection warning, updated sql injection section, changed mock emails

* Removed in preview from Interactive Transactions

* fixed query

* Removed section about template literals, fixed query

* Minor change

* Revert removal of in preview tags

* Removed link to issue
* Fixes #2084

* Fixes #2085

* Fixes #2088

* Fixes #2093

* Changed title of section, moved content and deleted tls section
* SQL Server boolean type is bit

* Note about decimal parameters

* No need for params, when describing allowed types

* bit is not bytes!
* Fix SQL Server feature matrix

- No support for `RESTRICT` action
- JSON support is only partial

* Fix phrasing
* Added note of until version 3 the signiture was...

* Fixed codeblocks inside quote blocks
* Updated db seed docs

* Trigger build

* Chnaged to require syntax

* Update content/300-guides/050-database/300-seed-database.mdx

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>

* Feedback changes

* Simplified copy and seed field

* Added note about compile options when using nextjs

* Update content/300-guides/050-database/300-seed-database.mdx

Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>

* Update content/300-guides/050-database/300-seed-database.mdx

Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>

* Changed copy according to feedback

* Update content/300-guides/050-database/300-seed-database.mdx

Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>

* Moved migrate section and added more context

* Fixed alignment bug causing failed builds

Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
* Update 060-full-text-search.mdx (#2218)

* Update 060-full-text-search.mdx

Unfortunately pipes can't be escaped in our docs markdown parser right now.

* Fixed code in md table with pipe

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Small fixes in self relation docs (#2221)

- Fix a minor heading level inconsistency 
- Fix an issue with incorrect code highlighting

* fix(codemods): Fix title (#2224)

* fix(deps): update dependency @prisma/lens to v0.0.222

* fix(deps): update dependency @prisma/lens to v0.0.223

* fix(deps): update dependency @prisma/lens to v0.0.224

* fix(logging): Fix highlighted line in code (#2230)

* fix(use-custom-model-and-field-names): Fix a typo (#2228)

* feat(environment-variables): Expand env vars from system env, not only .env file (#2208)

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* interactive transactions: update concept and tx guide with a better example (#2227)

* interactive transactions: update concept and tx guide with a better example

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* fix(deps): update dependency @prisma/lens to v0.0.223

* fix(deps): update dependency @prisma/lens to v0.0.224

* fix(logging): Fix highlighted line in code (#2230)

* fix(use-custom-model-and-field-names): Fix a typo (#2228)

* feat(environment-variables): Expand env vars from system env, not only .env file (#2208)

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* add spacing between header

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Vespaiach <nta.toan@gmail.com>
Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Add to existing project sql server guide

* Feedback changes

Co-authored-by: Matthew Mueller <mattmuelle@gmail.com>
Co-authored-by: Tasin Ishmam <tasinishmam@gmail.com>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Vespaiach <nta.toan@gmail.com>
Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>
molebox and others added 7 commits September 3, 2021 09:08
* Update 060-full-text-search.mdx (#2218)

* Update 060-full-text-search.mdx

Unfortunately pipes can't be escaped in our docs markdown parser right now.

* Fixed code in md table with pipe

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Small fixes in self relation docs (#2221)

- Fix a minor heading level inconsistency 
- Fix an issue with incorrect code highlighting

* fix(codemods): Fix title (#2224)

* fix(deps): update dependency @prisma/lens to v0.0.222

* fix(deps): update dependency @prisma/lens to v0.0.223

* fix(deps): update dependency @prisma/lens to v0.0.224

* fix(logging): Fix highlighted line in code (#2230)

* fix(use-custom-model-and-field-names): Fix a typo (#2228)

* upgrade to prisma 3 guide plus structural changes

* feat(environment-variables): Expand env vars from system env, not only .env file (#2208)

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* interactive transactions: update concept and tx guide with a better example (#2227)

* interactive transactions: update concept and tx guide with a better example

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* fix(deps): update dependency @prisma/lens to v0.0.223

* fix(deps): update dependency @prisma/lens to v0.0.224

* fix(logging): Fix highlighted line in code (#2230)

* fix(use-custom-model-and-field-names): Fix a typo (#2228)

* feat(environment-variables): Expand env vars from system env, not only .env file (#2208)

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/100-performance-and-optimization/100-prisma-client-transactions-guide.mdx

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Update content/200-concepts/100-components/02-prisma-client/058-transactions.mdx

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* add spacing between header

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Vespaiach <nta.toan@gmail.com>
Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Refactor

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/100-named-constraints.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/100-named-constraints.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/100-named-constraints.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/100-named-constraints.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/050-upgrading-to-prisma-3/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/200-upgrading-versions/index.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* Update content/300-guides/300-upgrade-guides/250-upgrading-to-use-preview-features.mdx

Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>

* small changes

* Chnaged order of breaking changes to match release notes

Co-authored-by: Matthew Mueller <mattmuelle@gmail.com>
Co-authored-by: Tasin Ishmam <tasinishmam@gmail.com>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Vespaiach <nta.toan@gmail.com>
Co-authored-by: Hervé Labas <431257+thebiglabasky@users.noreply.github.com>
Comment on lines +190 to +219
### Related: Naming indexes and primary keys for Prisma Client

Additionally to `map`, the `@@id` and `@@unique` attributes take an optional `name` argument that allows you to customize your Prisma client API.

On a model like:

```prisma
model User {
firstName String
lastName String

@@id([firstName, lastName])
}
```

the default API for selecting on that primary key uses a generated combination of the fields:

```ts
prisma.user.findUnique({
where: { firstName_lastName: { firstName: 'Paul', lastName: 'Panther' } },
})
```

Specifying `@@id([firstName, lastName], name: "fullName")` will change the Prisma Client API to this instead:

```ts
prisma.user.findUnique({
where: { fullName: { firstName: 'Paul', lastName: 'Panther' } },
})
```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this section to the bottom as I think it is not really about "Names in the underlying database" but certainly related and relevant. Also changed the order of the description to go from default to customized and actually show the model this changes.

Comment on lines 79 to 95
Additionally, the `@@id` and `@@unique` attributes take an optional `name` argument that allows you to customize your Prisma client API.

Specifying `@@id([firstName, lastName], name: "fullName")` will allow you to do

```ts
prisma.user.findUnique({
where: { fullName: { firstName: 'Paul', lastName: 'Panther' } },
})
```

instead of:

```ts
prisma.user.findUnique({
where: { firstName_lastName: { firstName: 'Paul', lastName: 'Panther' } },
})
```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +20 to +24
Sometimes the names used to describe entities in your database might not match the names you would prefer in your generated API. Mapping names in the Prisma schema allows you to influence the naming in your Client Api without having to change the underlying database names.

A common approach for naming tables/collections in databases for example is to use plural form and [snake_case](https://en.wikipedia.org/wiki/Snake_case) notation. Prisma on the other hand has recommended model [naming conventions (singular form, PascalCase)](../../../reference/api-reference/prisma-schema-reference#naming-conventions) <span class="api"></span> which differ from that.

`@map` and `@@map` allow you to [tune the shape of your Prisma Client API](../prisma-client/working-with-prismaclient/use-custom-model-and-field-names#using-map-and-map-to-rename-fields-and-models-in-the-prisma-client-api) by decoupling model and field names from table and column names in the underlying database.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different sentences from all over the document create this new "introduction"


```prisma
model comments {
// Fields
}
```

However, you can still follow the naming convention without renaming the underlying `comments` table in the database by using the [`@@map`](../../../reference/api-reference/prisma-schema-reference#map-1) <span class="api"></span> attribute:
However, you can still choose `Comment` as the name of the model (e.g. to follow the naming convention) without renaming the underlying `comments` table in the database by using the [`@@map`](../../../reference/api-reference/prisma-schema-reference#map-1) <span class="api"></span> attribute:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deemphasize the naming convention, most use cases will just be "I like it better this way"

@@ -55,6 +59,8 @@ model Comment {
}
```

This way the `comment_text` column is not available under `prisma.comment.comment_text` in the Prisma Client API, but can be accessed via `prisma.comment.content`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what this means in the API

@@ -68,31 +74,9 @@ enum Type {
}
```

`@map` and `@@map` allow you to [tune the shape of your Prisma Client API](../prisma-client/working-with-prismaclient/use-custom-model-and-field-names#using-map-and-map-to-rename-fields-and-models-in-the-prisma-client-api) by decoupling model and field names from table and column names in the underlying database.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -101,6 +85,9 @@ Custom constraint and index names are currently not supported by MongoDB.

</Admonition>


When introspecting a database, the `map` argument will _only_ be rendered in the schema the name differs from Prisma's [default constraint naming convention for indexes and constraints](#prismas-default-naming-conventions-for-indexes-and-constraints).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO move

Comment on lines +149 to +154
| Constraint or index | Follows convention | Underlying constraint or index names |
| ---------------------------------- | ------------------ | ------------------------------------ |
| `@id` (on `User` > `id` field) | Yes | `User_pk` |
| `@@index` (on `Post`) | Yes | `Post_title_authorName_idx` |
| `@id` (on `Post` > `id` field) | Yes | `Post_pk` |
| `@relation` (on `Post` > `author`) | Yes | `Post_authorName_fkey` |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New table that shows how the deafault names all look like

Base automatically changed from epic/prisma-3 to main September 7, 2021 15:58
@janpio
Copy link
Contributor Author

janpio commented Feb 18, 2022

Replaced by #2902

@janpio janpio closed this Feb 18, 2022
@janpio janpio deleted the names-in-underlying-database-iterate branch February 18, 2022 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants