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

feat(cli): add Driver Adapters and underlying drivers to prisma -v #24448

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Jun 6, 2024

This PR closes https://github.com/prisma/team-orm/issues/379.

It modifies prisma -v so that:

  • (Well-known, @prisma/adapter-*) Driver Adapters' versions are read and displayed
  • For each Driver Adapter, the underlying driver and its version is also displayed

Driver Adapters are not shown when using the binary Query Engine.


Consider the following package.json:

{
  "dependencies": {
    "@prisma/adapter-d1": "file:../adapter-d1",
    "@prisma/adapter-neon": "file:../adapter-neon",
    "@prisma/adapter-pg": "file:../adapter-pg",
    "@prisma/adapter-planetscale": "file:../adapter-planetscale",
    "@prisma/adapter-not-recognized": "file:../adapter-not-recognized",
    "@prisma/non-adapter": "file:../non-adapter",
    "@prisma/client": "file:../client",
    "@neondatabase/serverless": "<NEON_VERSION>"
  },
  "devDependencies": {
    "wrangler": "<WRANGLER_DEV_VERSION>",
    "pg": "<PG_DEV_VERSION>"
  }
}

Then, prisma -v would now display:

prisma                      : 0.0.0
@prisma/client              : 0.0.0
+ @prisma/adapter-d1          : file:../adapter-d1
+  ↳ wrangler                 : <WRANGLER_DEV_VERSION>
+ @prisma/adapter-neon        : file:../adapter-neon
+  ↳ @neondatabase/serverless : <NEON_VERSION>
+ @prisma/adapter-pg          : file:../adapter-pg
+  ↳ pg                       : Not found
+ @prisma/adapter-planetscale : file:../adapter-planetscale
+  ↳ @planetscale/database    : Not found
Computed binaryTarget       : TEST_PLATFORM
Operating System            : OS
Architecture                : ARCHITECTURE
Node.js                     : NODEJS_VERSION
Query Engine (Node-API)     : libquery-engine ENGINE_VERSION (at sanitized_path/libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node, resolved by PRISMA_QUERY_ENGINE_LIBRARY)
Schema Engine               : schema-engine-cli ENGINE_VERSION (at sanitized_path/schema-engine-TEST_PLATFORM, resolved by PRISMA_SCHEMA_ENGINE_BINARY)
Schema Wasm                 : @prisma/prisma-schema-wasm CLI_VERSION.ENGINE_VERSION
Default Engines Hash        : ENGINE_VERSION
Studio                      : STUDIO_VERSION"
....

Notes:

  • @prisma/adapter-not-recognized is not a valid / well-known Driver Adapter, so it's not included in the output.
  • @prisma/adapter-planetscale is found, but its underlying driver, @planetscale/database, isn't. That's because it's not installed in package.json.
  • @prisma/adapter-pg is found, but its underlying driver, pg, isn't. That's because it doesn't appear in dependencies.
  • @prisma/adapter-d1 is found, and its underlying driver, wrangler, is also found. This is the only case in which the underlying driver can be retrieved from devDependencies (@prisma/client needs these drivers at runtime).

@jkomyno jkomyno self-assigned this Jun 6, 2024
@jkomyno jkomyno added this to the 5.16.0 milestone Jun 6, 2024
Copy link
Contributor

github-actions bot commented Jun 6, 2024

size-limit report 📦

Path Size
packages/client/runtime/library.js 179.82 KB (0%)
packages/client/runtime/library.d.ts 81 B (0%)
packages/client/runtime/binary.js 600.89 KB (0%)
packages/client/runtime/binary.d.ts 26 B (0%)
packages/client/runtime/edge.js 159.02 KB (0%)
packages/client/runtime/edge-esm.js 158.91 KB (0%)
packages/client/runtime/wasm.js 114.9 KB (0%)
packages/client/runtime/index-browser.js 33.77 KB (0%)
packages/client/runtime/index-browser.d.ts 89 B (0%)
packages/cli/build/index.js 2.1 MB (+0.05% 🔺)
packages/client/prisma-client-0.0.0.tgz 2.86 MB (-0.01% 🔽)
packages/cli/prisma-0.0.0.tgz 3.67 MB (+0.01% 🔺)
packages/bundle-size/da-workers-libsql/output.tgz 858.21 KB (0%)
packages/bundle-size/da-workers-neon/output.tgz 935.05 KB (0%)
packages/bundle-size/da-workers-pg/output.tgz 953.62 KB (0%)
packages/bundle-size/da-workers-pg-worker/output.tgz 909.33 KB (0%)
packages/bundle-size/da-workers-planetscale/output.tgz 871.06 KB (0%)
packages/bundle-size/da-workers-d1/output.tgz 830.29 KB (0%)

@jkomyno jkomyno marked this pull request as ready for review June 6, 2024 12:04
@jkomyno jkomyno requested a review from a team as a code owner June 6, 2024 12:04
@jkomyno jkomyno requested review from SevInf and removed request for a team June 6, 2024 12:04
janpio
janpio previously approved these changes Jun 6, 2024

const adapterVersionsWithUnderlyingDrivers = adapterVersions.map(([adapterName, adapterVersion]) => {
const underlyingDriver = underlyingDriverAdaptersMap[adapterName]
let underlyingDriverVersion = pkgJson.dependencies?.[underlyingDriver] ?? null
Copy link
Contributor

Choose a reason for hiding this comment

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

So, that potentially will give us a version range, not the actual version: (^5.0.0 can really be any version of Prisma 5). Can we try to require (const require = createRequire(pkgJsonPath); require(adapterName).version the package and fallback onto the range only if that fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't the behavior you're suggesting be different than what prisma version currently does?
I agree that having the precise version would be better, but if this is a new kind of logic, perhaps that should be applied in a different PR (?)

Copy link
Contributor

@SevInf SevInf Jun 6, 2024

Choose a reason for hiding this comment

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

Is it different? Engines and prisma cli version are known to cli for sure and for @prisma/client version we actually try to require it in a similar way I am suggesting

Copy link
Member

Choose a reason for hiding this comment

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

prisma -v currently shows the actually installed versions, not just the content of package.json.

Comment on lines +82 to +85
// `wrangler` is the only underlying driver that can be just a `devDependency`.
if (underlyingDriverVersion === null && underlyingDriver === 'wrangler') {
underlyingDriverVersion = pkgJson.devDependencies?.[underlyingDriver] ?? null
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should look in dependencies too because people will sometimes put it there as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact we look into dependencies just a couple of lines earlier :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, then I would say the opposite 😄

In general this makes sense.

But it's possible that people misplace the adapter packages and place them in devDependencies, and we should look in both places without assuming they would only be for sure in "devDependencies" or "dependencies".

Copy link
Contributor

@Jolg42 Jolg42 Jun 6, 2024

Choose a reason for hiding this comment

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

TLDR: we better not have any assumption on where any packages are placed

* E.g., `@prisma/adapter-planetscale` -> `@planetscale/database`
*/

export const underlyingDriverAdaptersMap = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this module would make more sense as a part of cli, not driver-adapter-utils:

  • cli is the only one using it and I don't see that changing anytime soon
  • it's weird that generic library with building blocks and abastractions for specific drivers now has a list of all specific adapters hardcoded.

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.

None yet

4 participants