Skip to content

Commit

Permalink
Update introspection.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Oct 23, 2019
1 parent bebf384 commit 393d2a0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/introspection.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Introspection

When working with an existing database, the first step towards using the Prisma Framework is to obtain a [Prisma schema](./prisma-schema-file.md) that matches your database schema (or a subset of your database schema). You can create this schema file manually and write out all the required [models](./data-modeling.md#models) by hand, or use Prisma's _introspection_ feature to automatically generate your Prisma schema.

Prisma lets you introspect your database to derive a data model definition from the current database schema. Introspection is available via two CLI commands:

- `prisma init`: Interactive wizard that helps you connect to a database and introspect it. Typically used when starting to use Prisma with an existing database.
- `prisma introspect`: Assumes Prisma is already connected to your database and (re)introspects it for you. Typically used in [Photon-only](./photon/use-only-photon.md) projects where migrations are performed not via Lift, so the data model needs to be updated manually after each database schema change.

## Introspecting only a subset of your database schema

This is [not yet supported by Prisma](https://github.com/prisma/prisma2/issues/807). However, you can achieve this by creating a new database user that only has access to the tables which you'd like to see represented in your Prisma schema, and then perform the introspection using that user. The introspection will then only include the tables the new user has access to.

## Conventions

As database schemas are likely to look very different per project, Prisma employs a number of conventions for translating a database schema into a data model definition.
Expand All @@ -31,4 +37,4 @@ As database schemas are likely to look very different per project, Prisma employ

### Keeping manual changes in the Prisma schemas

In the TS implementation, the data model that's generated from an introspection is merged with the existing data model, and the naming in the existing data model always takes precedence. Matching fields (in case fields were renamed) are identified by _name_, _id property_ and _relation type_, in that order.
In the TS implementation, the data model that's generated from an introspection is merged with the existing data model, and the naming in the existing data model always takes precedence. Matching fields (in case fields were renamed) are identified by _name_, _id property_ and _relation type_, in that order.

0 comments on commit 393d2a0

Please sign in to comment.