Skip to content

Commit

Permalink
update docs for binaryTargets
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Nov 25, 2019
1 parent 3e5de48 commit 480d718
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
19 changes: 11 additions & 8 deletions docs/core/generators/photonjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ To determine the platform Photon is running on, you can provide two options to t

| Name | Required | Description | Purpose |
| ---------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| `platforms` | No | An array of binaries that are required by the application. Either a _file path_ to a binary, a package name from the [available binaries](#available-binaries) or the special value `"native"`. **Default**: `["native"]`. | Declarative way to download the required binaries. |
| `pinnedPlatform` | Only if `platforms` contains a _file path_ to a binary | A string that points to the name of an object in the `platforms` field (typically an environment variable). Requires the `platforms` options to be a non-empty array. | Declarative way to define which binary to use at runtime. |
| `binaryTargets` | No | An array of binary names that are required by the application. Either a _file path_ to a binary, a package name from the [available binaries](#available-binaries) or the special value `"native"`. **Default**: `["native"]`. | Declarative way to download the required binaries. |

If `binaryTargets` contains a _file path_ to a binary, you need to provide the path to the binary via an environment variable:

- If you're using a custom binary for the **query engine** (Photon.js), set the file path to it as the `PRISMA_QUERY_ENGINE_BINARY` environment variable.
- If you're using a custom binary for the **migration engine** (Lift), set the file path to it as the `PRISMA_MIGRATION_ENGINE_BINARY` environment variable.

### Default: The `native` platform

When no [generator options](#generator-options) are passed to the `photonjs` generator in your [Prisma schema file](../prisma-schema-file.md), the Prisma CLI will download the binary for the operating system on which `prisma2 generate` was executed. The following two configurations are therefore equivalent, because `["native"]` is the default value for `platforms`:
When no [generator options](#generator-options) are passed to the `photonjs` generator in your [Prisma schema file](../prisma-schema-file.md), the Prisma CLI will download the binary for the operating system on which `prisma2 generate` was executed. The following two configurations are therefore equivalent, because `["native"]` is the default value for `binaryTargets`:

```groovy
generator photon {
provider = "photonjs"
platforms = ["native"]
binaryTargets = ["native"]
}
```

Expand All @@ -58,9 +62,8 @@ This example shows the configuration of a Photon.js generator for local developm

```groovy
generator photon {
provider = "photonjs"
platforms = ["native", "linux-glibc-libssl1.0.2"] // For Lambda (Node 10)
pinnedPlatform = env("PLATFORM") // Local: "native"; In production: "linux-glibc-libssl1.0.2"
provider = "photonjs"
binaryTargets = ["native", "debian-glibc-libssl-1.0.2"]
}
```

Expand Down Expand Up @@ -93,7 +96,7 @@ Once added, you can invoke the generator using the following command:
prisma2 generate
```

It will then store the generated Photon API in the specified `./generated/photon` directory. Learn more about the [generated Photon API](../../photon/api.md).
It will then store the generated Photon API in the default location `node_modules/@prisma/photon` directory. Learn more about the [generated Photon API](../../photon/api.md).

## Mapping types from the data model

Expand Down
30 changes: 11 additions & 19 deletions docs/prisma-schema-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The Prisma schema file (short: _schema file_, _Prisma schema_ or _schema_) is th
Whenever a `prisma2` command is invoked, the CLI typically reads some information from the schema file, e.g.:

- `prisma2 generate`: Reads _all_ above mentioned information from the Prisma schema to generate the correct data source client code (e.g. Photon.js).
- `prisma2 lift save`: Reads the data sources and data model definition to create a new [migration]().
- `prisma2 lift save`: Reads the data sources and data model definition to create a new [migration]().

You can also [use environment variables](#using-environment-variables) inside the schema file to provide configuration options when a CLI command is invoked.

Expand Down Expand Up @@ -68,7 +68,6 @@ If the schema file is named differently, you can provide an explicit option to t
The schema file is written in Prisma Schema Language (PSL). You can find a full reference for PSL in the
[spec](https://github.com/prisma/specs/tree/master/prisma-schema).


## Building blocks

### Data sources
Expand Down Expand Up @@ -143,15 +142,14 @@ A generator configures what data source clients are generated and how they're ge

#### Fields

| Name | Required | Type | Description |
| ---------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `provider` | **Yes** | String (file path) or Enum (`photonjs`, `nexus-prisma`) | Describes which generator to use. This can point to a file that implements a generator or specify a built-in generator directly. |
| `output` | **Yes** | String (file path) | Determines the location for the generated client. |
| `platforms` | _(optional)_ | List of Enums (prebuilt binaries [available here](https://github.com/prisma/specs/blob/master/binaries/Readme.md#table-of-binaries)) or Strings (path to custom binary) | Declarative way to download the required binaries. |
| `pinnedPlatform` | _(optional)_ | String (pointing to the platform) | Declarative way to choose the runtime binary |
| Name | Required | Type | Description |
| --------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `provider` | **Yes** | String (file path) or Enum (`photonjs`, `nexus-prisma`) | Describes which generator to use. This can point to a file that implements a generator or specify a built-in generator directly. |
| `output` | **Yes** | String (file path) | Determines the location for the generated client. |
| `binaryTargets` | _(optional)_ | List of Enums (prebuilt binaries [available here](https://github.com/prisma/specs/blob/master/binaries/Readme.md#table-of-binaries)). | Declarative way to download the required binaries. |

- A generator may bring its own fields to allow users to customize the generation behaviour.
- Both `platforms` and `pinnedPlatform` fields are optional, **however** when a custom binary is provided the `pinnedPlatform` is required.
- Both `binaryTargets`.

#### Examples

Expand All @@ -165,23 +163,17 @@ generator js_custom_output {
output = "../src/generated/photon"
}
generator nexus_prisma {
provider = "nexus-prisma"
}
generator ts {
provider = "./path/to/custom/generator"
}
generator ts {
provider = "./path/to/custom/generator"
platforms = ["native", "linux-glibc-libssl1.0.2"]
pinnedPlatform = env("PLATFORM") // On local set to "native"; in production set to "linux-glibc-libssl1.0.2"
provider = "./path/to/custom/generator"
binaryTargets = ["native", "linux-glibc-libssl1.0.2"]
}
```

> **Note**: The default `output` for the `photonjs` and `nexus-prisma` providers is your `node_modules` directory. This can be customized as seen in the second
> example in the code snippet above.
> **Note**: The default `output` for the `photonjs` provider is your `node_modules` directory. This can be customized as seen in the second example in the code snippet above.
### Data model definition

Expand Down Expand Up @@ -214,7 +206,7 @@ datasource pg {
```

> Unfortunately, you cannot use string concat operations to build your url for now.
### Switching data sources based on environments

> This feature [is not implemented yet](https://github.com/prisma/prisma2/issues/265#issuecomment-515955670). As a workaround you can provide environment variables for both `url` and `provider` options.
Expand Down

0 comments on commit 480d718

Please sign in to comment.