Skip to content

feat(client): enforce driverAdapters preview feature - #21163

Merged
aqrln merged 7 commits into
mainfrom
driver-adapters-enforce-preview-feature
Sep 27, 2023
Merged

aqrln merged 7 commits into
mainfrom
driver-adapters-enforce-preview-feature

Conversation

@aqrln

@aqrln aqrln commented Sep 20, 2023 •

Copy link
Copy Markdown
Member
  • Enforce driverAdapters preview feature to use driver adapters at run time and not just on type level.
  • Minor refactoring along the way: make getPrismaClient options validators type-safe.
  • Add functional tests helpers for testing infrastructure around driver adapters.

@aqrln aqrln changed the title refactor(client): make validators type safe and accept whole config feat(client): enforce driverAdapters preview feature Sep 20, 2023
@aqrln aqrln added this to the 5.4.0 milestone Sep 20, 2023
@github-actions

github-actions Bot commented Sep 20, 2023 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
packages/client/runtime/library.d.ts 97.06 KB (0%)
packages/client/runtime/library.js 179.36 KB (+0.13% 🔺)
packages/client/runtime/binary.js 601.29 KB (+0.04% 🔺)
packages/client/runtime/edge.js 208.84 KB (+0.11% 🔺)
packages/cli/build/index.js 5.07 MB (0%)

@aqrln
aqrln marked this pull request as ready for review September 20, 2023 17:25
@aqrln
aqrln requested a review from a team as a code owner September 20, 2023 17:25
@aqrln
aqrln requested review from Jolg42 and jkomyno and removed request for a team September 20, 2023 17:25
@aqrln
aqrln requested a review from SevInf September 20, 2023 19:28

@SevInf SevInf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left a couple of suggestions. I don't think any of them are blocking and strictly required for this to get merged, feel free to ignore or do them in follow up PRs.

@janpio
janpio requested review from Jolg42, jkomyno and millsp and removed request for Jolg42 and jkomyno September 26, 2023 12:12
- Make `getPrismaClient` options validators type-safe
- Accept the whole config instead of just `datasourceNames`
- Implement driver-adapters test infrastructure
- Add `enforce-preview-feature` test in `driver-adapters` directory
@aqrln
aqrln force-pushed the driver-adapters-enforce-preview-feature branch from 81e85a6 to 296b23f Compare September 27, 2023 14:48

@millsp millsp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Neat!

@millsp

millsp commented Sep 27, 2023 •

Copy link
Copy Markdown
Contributor

The failing tests are expected as we are automatically adding the preview feature flags when you run with --flavor, that will mess with your test. You could use skipTestIf(driverAdapter)(..., this variable is available in clientMeta.

@aqrln
aqrln merged commit 2c665a8 into main Sep 27, 2023
@aqrln
aqrln deleted the driver-adapters-enforce-preview-feature branch September 27, 2023 17:28
aqrln added a commit that referenced this pull request Oct 2, 2023
Throw on explicit `undefined` value of `adapter` (but not on missing
property) and allow `null` to conditionally or explicitly disable driver
adapters, as suggested in <#21163 (comment)>.

Closes prisma/team-orm#388
aqrln added a commit that referenced this pull request Nov 3, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
aqrln added a commit that referenced this pull request Nov 17, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
aqrln added a commit that referenced this pull request Nov 17, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
aqrln added a commit that referenced this pull request Nov 17, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants