Skip to content

Conversation

@jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Mar 29, 2024

This PR:

In particular, it:

  • adds the --from-local-d1 and --to-local-d1 boolean flags to prisma migrate diff. They locate the local Cloudflare D1 database automatically, if it exists.
  • adds the --local-d1 boolean flag to prisma db pull. It locate the local Cloudflare D1 database automatically, if it exists.
    • When schema.prisma exists already, it overrides it. If the schema had no "driverAdapters" preview feature, the following warning is emitted:

      Without the driverAdapters preview feature, the schema introspected via the --local-d1 flag will not work with @prisma/client.
      

      Screenshot 2024-03-29 at 17 40 14

    • When no schema.prisma exists, it generates it in ./schema.prisma (rather than ./prisma/schema.prisma, matching the same location used by --url), including a generator client block with the "driverAdapters" preview feature.

    • An introspected datasource looks like:

      datasource db {
        provider = "sqlite"
        url      = "file:../.wrangler/state/v3/d1/miniflare-D1DatabaseObject/5d11bcce386042472d19a6a4f58e40041ebc5932c972e1449cbf404f3e3c4a7a.sqlite"
      }
  • adds argument validation
  • adds tests for prisma migrate diff
  • adds tests for prisma db pull
  • I've also manually tested this PR against a Cloudflare Worker

How is a local Cloudflare D1 database located?

Let's see an example when using migrate diff --from-local-d1:

  1. Prisma looks into .wrangler/state/v3/d1/miniflare-D1DatabaseObject/<UUID>.sqlite.
  2. If no .sqlite file exists, the following error is emitted:
No Cloudflare D1 databases found in .wrangler/state/v3/d1/miniflare-D1DatabaseObject/<UUID>.sqlite.
Did you run `wrangler d1 create <DATABASE_NAME>` and `wrangler dev`?
  1. If multiple .sqlite files exist, the following error are emitted:
Multiple Cloudflare D1 databases found in .wrangler/state/v3/d1/miniflare-D1DatabaseObject.
Please manually specify the local D1 database with `--from-url file:`, without using the `--from-local-d1` flag.`,

This logic is shared between prisma migrate diff and prisma db pull, and lives in packages/internals/src/utils/cloudflareD1.ts.

@jkomyno jkomyno added this to the 5.12.0 milestone Mar 29, 2024
@jkomyno jkomyno self-assigned this Mar 29, 2024
@jkomyno jkomyno marked this pull request as ready for review March 29, 2024 15:32
@jkomyno jkomyno requested a review from a team as a code owner March 29, 2024 15:32
@jkomyno jkomyno requested review from SevInf and removed request for a team March 29, 2024 15:32
@github-actions
Copy link
Contributor

github-actions bot commented Mar 29, 2024

size-limit report 📦

Path Size
packages/client/runtime/library.js 177.48 KB (0%)
packages/client/runtime/library.d.ts 81 B (0%)
packages/client/runtime/binary.js 596.3 KB (0%)
packages/client/runtime/binary.d.ts 26 B (0%)
packages/client/runtime/edge.js 156.41 KB (0%)
packages/client/runtime/edge-esm.js 156.3 KB (0%)
packages/client/runtime/wasm.js 112.62 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.73 MB (+0.1% 🔺)
packages/client/prisma-client-0.0.0.tgz 2.89 MB (0%)
packages/cli/prisma-0.0.0.tgz 3.88 MB (+0.03% 🔺)
packages/bundle-size/da-workers-libsql/output.tgz 863.76 KB (0%)
packages/bundle-size/da-workers-neon/output.tgz 941.69 KB (0%)
packages/bundle-size/da-workers-pg/output.tgz 963.11 KB (0%)
packages/bundle-size/da-workers-pg-worker/output.tgz 916.23 KB (0%)
packages/bundle-size/da-workers-planetscale/output.tgz 878.66 KB (0%)
packages/bundle-size/da-workers-d1/output.tgz 836.83 KB (0%)

@Jolg42 Jolg42 self-requested a review April 2, 2024 09:18
Copy link
Contributor

@Jolg42 Jolg42 left a comment

Choose a reason for hiding this comment

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

Nice 🙌🏼

@Jolg42 Jolg42 merged commit b8f741a into main Apr 2, 2024
@Jolg42 Jolg42 deleted the integration/integrate-migrations-with-adapter-d1 branch April 2, 2024 11:47
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.

3 participants