diff --git a/content/200-concepts/100-components/01-prisma-schema/06-relations/300-many-to-many-relations.mdx b/content/200-concepts/100-components/01-prisma-schema/06-relations/300-many-to-many-relations.mdx index 4433a1735f..c46d607cd1 100644 --- a/content/200-concepts/100-components/01-prisma-schema/06-relations/300-many-to-many-relations.mdx +++ b/content/200-concepts/100-components/01-prisma-schema/06-relations/300-many-to-many-relations.mdx @@ -350,19 +350,23 @@ Implicit m-n relations: If you obtain your data model from [introspection](/concepts/components/introspection), you can still use implicit m-n-relations by following Prisma's [conventions for relation tables](#conventions-for-relation-tables-in-implicit-m-n-relations). The following example assumes you want to create a relation table to get an implicit m-n-relation for two models called `Post` and `Category`. -##### Table names +##### Relation table If you want a relation table to be picked up by introspection as an implicit m-n-relation, the name must follow this exact structure: - It must start with an underscore `_` -- Then the name of the first table in alphabetical order (in this case `Category`) +- Then the name of the first model in alphabetical order (in this case `Category`) - Then `To` -- Then the name of the second table in alphabetical order (in this case `Post`) +- Then the name of the second model in alphabetical order (in this case `Post`) In the example, the correct table name is `_CategoryToPost`. When creating an implicit m-n-relation yourself in the Prisma schema file, you can [configure the relation](#configuring-the-name-of-the-relation-table-in-implicit-many-to-many-relations) to have a different name. This will change the name given to the relation table in the database. For example, for a relation named `"MyRelation"` the corresponding table will be called `_MyRelation`. +###### Multi-schema + +If your implicit many-to-many relationship spans multiple database schemas (using the [`multiSchema` preview feature](/guides/database/multi-schema)), the relation table (with the name defined directly above, in the example `_CategoryToPost`) must be present in the same database schema as the first model in alphabetical order (in this case `Category`). + ##### Columns A relation table for an implicit m-n-relation must have exactly two columns: diff --git a/content/300-guides/125-development-environment/050-environment-variables/040-env-files.mdx b/content/300-guides/125-development-environment/050-environment-variables/040-env-files.mdx new file mode 100644 index 0000000000..94d6acac28 --- /dev/null +++ b/content/300-guides/125-development-environment/050-environment-variables/040-env-files.mdx @@ -0,0 +1,93 @@ +--- +title: '.env files' +metaTitle: '.env files' +metaDescription: 'Configure environment variables using .env files in Prisma' +--- + + + +Prisma creates a default `.env` file at your projects root. You can choose to replace this file or create a new one in the `prisma` folder, or if you choose to relocate your `prisma.schema` file, alongside that. + + + +### .env file locations + +The Prisma CLI looks for `.env` files, in order, in the following locations: + +1. In the root folder of your project (`./.env`) +1. From the same folder as the schema specified by the `--schema` argument +1. From the same folder as the schema taken from `"prisma": {"schema": "/path/to/schema.prisma"}` in `package.json` +1. From the `./prisma` folder + +If a `.env` file is located in step 1., but additional, clashing `.env` variables are located in steps 2. - 4., the CLI will throw an error. For example, if you specify a `DATABASE_URL` variable in two different `.env` files, you will get the following error: + +``` +Error: There is a conflict between env vars in .env and prisma/.env +Conflicting env vars: + DATABASE_URL + +We suggest to move the contents of prisma/.env to .env to consolidate your env vars. +``` + +The following table describes where the Prisma CLI looks for the `.env` file: + +| **Command** | **Schema file location** | **`.env` file locations checked, in order** | +| :---------------------------------------------- | :--------------------------------------------------------------------------- | :-------------------------------------------------------- | +| `prisma [command]` | `./prisma/schema.prisma` | `./.env`
`./prisma/.env` | +| `prisma [command] --schema=./a/b/schema.prisma` | `./a/b/schema.prisma` | `./.env`
`./a/b/.env`
`./prisma/.env` | +| `prisma [command]` | `"prisma": {"schema": "/path/to/schema.prisma"}` | `.env`
`./path/to/schema/.env`
`./prisma/.env` | +| `prisma [command]` | No schema (for example, when running `prisma db pull` in an empty directory) | `./.env`
`./prisma/.env` | + +Any environment variables defined in that `.env` file will automatically be loaded when running a Prisma CLI command. + + + +**Do not commit your `.env` files into version control**! + + + +Refer to the `dotenv` documentation for information about [what happens if an environment variable is defined in two places](https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set). + +### Expanding variables + +Variables stored in `.env` files can be expanded using the format specified by [dotenv-expand](https://github.com/motdotla/dotenv-expand). + +```env file=.env +DATABASE_URL=postgresql://test:test@localhost:5432/test +DATABASE_URL_WITH_SCHEMA=${DATABASE_URL}?schema=public +``` + +This will make the environment variable `DATABASE_URL_WITH_SCHEMA` with value `postgresql://test:test@localhost:5432/test?schema=public` available for Prisma. + +You can also use environment variables in the expansion that are set _outside_ of the `.env` file, for example a database URL that is set on a PaaS like Heroku or similar: + +```terminal +# environment variable already set in the environment of the system +export DATABASE_URL=postgresql://test:test@localhost:5432/test +``` + +```env file=.env +DATABASE_URL_WITH_SCHEMA=${DATABASE_URL}?schema=foo +``` + +This will make the environment variable `DATABASE_URL_WITH_SCHEMA` with value `postgresql://test:test@localhost:5432/test?schema=foo` available for Prisma. + +### Example: Set the `DATABASE_URL` environment variable in an `.env` file + +It is common to load your database connection URL from an environment variable: + +```prisma +// schema.prisma +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} +``` + +You can set the `DATABASE_URL` in your `.env` file: + +```env file=.env +DATABASE_URL=postgresql://test:test@localhost:5432/test?schema=public +``` + +When you run a command that needs access to the database defined via the `datasource` block (for example, `prisma db pull`), the Prisma CLI automatically loads the `DATABASE_URL` environment variables from the `.env` file and makes it available to the CLI. diff --git a/content/300-guides/125-development-environment/050-environment-variables/index.mdx b/content/300-guides/125-development-environment/050-environment-variables/index.mdx index 1842b44ca8..f622c24bcd 100644 --- a/content/300-guides/125-development-environment/050-environment-variables/index.mdx +++ b/content/300-guides/125-development-environment/050-environment-variables/index.mdx @@ -19,6 +19,8 @@ The environment variable belongs to the environment where a process is running. Taking the `TEMP` environment variable as an example, one can query its value to find where to store temporary files. This is a system environment variable and can be queried by any process or application running on the machine. +Any program can read and create these environment variables. They are a cheap and effective way to store simple information. + ## How does Prisma use environment variables? @@ -33,92 +35,6 @@ Looking to use more than one `.env` file? See [Using multiple `.env` files](./us -## Using .env files - -Prisma creates a default `.env` file at your projects root. You can choose to replace this file or create a new one in the `prisma` folder, or if you choose to relocate your `schema.prisma` file, alongside that. - -### `.env` file locations - -The Prisma CLI looks for `.env` files, in order, in the following locations: - -1. In the root folder of your project (`./.env`) -1. From the same folder as the schema specified by the `--schema` argument -1. From the same folder as the schema taken from `"prisma": {"schema": "/path/to/schema.prisma"}` in `package.json` -1. From the `./prisma` folder - -If a `.env` file is located in step #1, but additional, clashing `.env` variables are located in steps #2 - 4, the CLI will throw an error. For example, if you specify a `DATABASE_URL` variable in two different `.env` files, you will get the following error: - -``` -Error: There is a conflict between env vars in .env and prisma/.env -Conflicting env vars: - DATABASE_URL - -We suggest to move the contents of prisma/.env to .env to consolidate your env vars. -``` - -The following table describes where the Prisma CLI looks for the `.env` file: - -| **Command** | **Schema file location** | **`.env` file locations checked, in order** | -| :---------------------------------------------- | :--------------------------------------------------------------------------- | :-------------------------------------------------------- | -| `prisma [command]` | `./prisma/schema.prisma` | `./.env`
`./prisma/.env` | -| `prisma [command] --schema=./a/b/schema.prisma` | `./a/b/schema.prisma` | `./.env`
`./a/b/.env`
`./prisma/.env` | -| `prisma [command]` | `"prisma": {"schema": "/path/to/schema.prisma"}` | `.env`
`./path/to/schema/.env`
`./prisma/.env` | -| `prisma [command]` | No schema (for example, when running `prisma db pull` in an empty directory) | `./.env`
`./prisma/.env` | - -Any environment variables defined in that `.env` file will automatically be loaded when running a Prisma CLI command. - - - -**Do not commit your `.env` files into version control**! - - - -Refer to the `dotenv` documentation for information about [what happens if an environment variable is defined in two places](https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set). - -### Expanding variables - -Variables stored in `.env` files can be expanded using the format specified by [dotenv-expand](https://github.com/motdotla/dotenv-expand). - -```env file=.env -DATABASE_URL=postgresql://test:test@localhost:5432/test -DATABASE_URL_WITH_SCHEMA=${DATABASE_URL}?schema=public -``` - -This will make the environment variable `DATABASE_URL_WITH_SCHEMA` with value `postgresql://test:test@localhost:5432/test?schema=public` available for Prisma. - -You can also use environment variables in the expansion that are set _outside_ of the `.env` file, for example a database URL that is set on a PaaS like Heroku or similar: - -```terminal -# environment variable already set in the environment of the system -export DATABASE_URL=postgresql://test:test@localhost:5432/test -``` - -```env file=.env -DATABASE_URL_WITH_SCHEMA=${DATABASE_URL}?schema=foo -``` - -This will make the environment variable `DATABASE_URL_WITH_SCHEMA` with value `postgresql://test:test@localhost:5432/test?schema=foo` available for Prisma. - -### Example: Set the `DATABASE_URL` environment variable in an `.env` file - -It is common to load your database connection URL from an environment variable: - -```prisma -// schema.prisma -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} -``` - -You can set the `DATABASE_URL` in your `.env` file: - -```env file=.env -DATABASE_URL=postgresql://test:test@localhost:5432/test?schema=public -``` - -When you run a command that needs access to the database defined via the `datasource` block (for example, `prisma db pull`), the Prisma CLI automatically loads the `DATABASE_URL` environment variables from the `.env` file and makes it available to the CLI. - ### Using environment variables in your code If you want environment variables to be evaluated at runtime, you need to load them manually in your application code (for example, by using [`dotenv`](https://github.com/motdotla/dotenv)): diff --git a/content/400-reference/200-api-reference/100-prisma-schema-reference.mdx b/content/400-reference/200-api-reference/100-prisma-schema-reference.mdx index e97e3fc2bb..3ee62fe8a7 100644 --- a/content/400-reference/200-api-reference/100-prisma-schema-reference.mdx +++ b/content/400-reference/200-api-reference/100-prisma-schema-reference.mdx @@ -176,12 +176,14 @@ A `generator` block accepts the following fields: The following tables list all supported operating systems with the name of platform to specify in [`binaryTargets`](/concepts/components/prisma-schema/generators#binary-targets). +Unless specified otherwise, the default supported CPU architecture is x86_64. + ##### macOS -| Build OS | Prisma engine build name | -| :-------------- | :----------------------- | -| macOS Intel x86 | `darwin` | -| macOS ARM64 | `darwin-arm64` | +| Build OS | Prisma engine build name | +| :----------------- | :----------------------- | +| macOS Intel x86_64 | `darwin` | +| macOS ARM64 | `darwin-arm64` | ##### Windows @@ -189,18 +191,23 @@ The following tables list all supported operating systems with the name of platf | :------- | :----------------------- | | Windows | `windows` | -##### Linux (Alpine) +##### Linux (Alpine on x86_64 architectures) -| Build OS | Prisma engine build name | OpenSSL | -| :------------------------------ | :----------------------------------- | :-----: | -| Alpine (3.16 and older), x86_64 | `linux-musl` | 1.1.x | -| Alpine (3.17 and newer), x86_64 | `linux-musl-openssl-3.0.x`\* | 3.0.x | -| Alpine (3.16 and older), ARM64 | `linux-musl-arm64-openssl-1.1.x`\*\* | 1.1.x | -| Alpine (3.17 and newer), ARM64 | `linux-musl-arm64-openssl-3.0.x`\*\* | 3.0.x | +| Build OS | Prisma engine build name | OpenSSL | +| :------------------ | :--------------------------- | :-----: | +| Alpine (3.17 and newer) | `linux-musl-openssl-3.0.x`\* | 3.0.x | +| Alpine (3.16 and older) | `linux-musl` | 1.1.x | \* Available in Prisma versions 4.8.0 and later. -\*\* Available in Prisma versions 4.10.0 and later. +##### Linux (Alpine on ARM64 architectures) + +| Build OS | Prisma engine build name | OpenSSL | +| :------------------ | :--------------------------------- | :-----: | +| Alpine (3.17 and newer) | `linux-musl-arm64-openssl-3.0.x`\* | 3.0.x | +| Alpine (3.16 and older) | `linux-musl-arm64-openssl-1.1.x`\* | 1.1.x | + +\* Available in Prisma versions 4.10.0 and later. ##### Linux (Debian), x86_64 @@ -259,7 +266,7 @@ The following tables list all supported operating systems with the name of platf | Arch Linux 2019.09.01 | `debian-openssl-1.1.x` | 1.1.x | | Arch Linux 2023.04.23 | `debian-openssl-3.0.x` | 3.0.x | -##### Linux (most distributions except Alpine), ARM64 +##### Linux ARM64 (all major distros but Alpine) | Build OS | Prisma engine build name | OpenSSL | | :----------------------------- | :-------------------------- | :-----: |