prisma: `migrate dev` is too slow when migrations directory is large

Bug description

Hello, Prisma team, thanks so much for this amazing tool 👐

I have been using Prisma Migrate in production for several months now. My schema has suffered a lot of changes and thus my migration directory is large (129 migrations as of now). Nowadays every time I execute migrate dev, the command takes a significant amount of time to be created. Screenshot below

image

image

It took around 5 minutes in these cases, even if no schema changes were required.

How to reproduce

I assume you can reproduce it with any Prisma project with 100+ migrations

Expected behavior

I’d like it to take no more than a minute, just like the early days of using Prisma Migrate. Or as an alternative, I’d like to get some indication of the progress it is making (similar to migrate reset, for example).

An option for me is also to delete ‘reset’ the migration history and start fresh without losing any data, I rarely use old migrations for anything. It would be useful to get an official workflow for his (maybe it would involve prisma introspect?)

Prisma information

This problem occurs on a Prisma project with 126 migrations and 24 MySQL tables.

Environment & setup

  • OS: Debian KDE Neon
  • Database: MySQL 8.0
  • Node.js version: 14.X

CPU info

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 43 bits physical, 48 bits virtual CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: AuthenticAMD CPU family: 23 Model: 24 Model name: AMD Ryzen 5 3400G with Radeon Vega Graphics Stepping: 1 Frequency boost: enabled CPU MHz: 1400.000 CPU max MHz: 3700.0000 CPU min MHz: 1400.0000 BogoMIPS: 7386.19 Virtualization: AMD-V L1d cache: 128 KiB L1i cache: 256 KiB L2 cache: 2 MiB L3 cache: 4 MiB NUMA node0 CPU(s): 0-7

Prisma Version

prisma                  : 3.8.1
@prisma/client          : 3.8.1
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio                  : 0.452.0

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 14
  • Comments: 19 (5 by maintainers)

Most upvoted comments

We now have some docs on squashing migrations that might be helpful: https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/squashing-migrations

Here is a CockroachDB specific issue @sastry-v: https://github.com/prisma/prisma/issues/12384

Hey @arvindell (and @motdde if you happen to work at the same company), can you maybe try to run npx prisma migrate dev --skip-generate so we get a cleaner view on the duration the actual migration takes? I suspect it will not make a huge difference - especially not compared to the total of 5 minutes, but still.

Additionally, this command might also be helpful to get some interesting debugging output in the terminal that might help us understand what is happening: DEBUG="prisma:migrate*" npx prisma migrate dev --skip-generate. Paste the full output if you can.

And for bonus points and the best solution, can you maybe share your schema and migrations with us so we can reproduce this? We can of course try to create something like this manually, but it would be super convenient if we could just use your migration history to see how that performs on our machines and then jump in what actually takes all that time when you run the command. (My email is jan@prisma.io and if needed we can of course also set up an NDA between our companies quickly - we have templates ready for that.)

I seem to be hitting something similar and don’t have many migrations that need to be applied. I can reproduce this reliably. Please let me know if you need anything else from my side to get to the bottom of this.

  • the Prisma version: 5.11.0
  • the OS: darwin
  • Node.js : v20.11.1
  • the database provider cockroachDB
  • is the CLI running close to the database? (e.g. remote or local database): Remote
  • how many migrations files are in the migrations directory: 5
  • the command and time it took from start to finish: DEBUG="prisma:migrate*" npx prisma migrate dev --skip-generate it took 30 mins

Here is the output:

% DEBUG="prisma:migrate*" npx prisma migrate dev --skip-generate
Prisma schema loaded from prisma/schema.prisma
Datasource "db": CockroachDB database "streamos", schema "public" at "aws-us-east-1.cockroachlabs.cloud:26257"

prisma:migrate:dev {
  "devDiagnostic": "{\n  \"action\": {\n    \"tag\": \"createMigration\"\n  }\n}"
} +1060558ms
Applying migration `20240327010319_new_column_request_comment`

The following migration(s) have been applied:

migrations/
  └─ 20240327010319_new_column_request_comment/
    └─ migration.sql
prisma:migrate:dev {
  "evaluateDataLossResult": {
    "migrationSteps": 0,
    "unexecutableSteps": [],
    "warnings": []
  }
} +556269ms
prisma:migrate:dev {
  "createMigrationResult": {
    "generatedMigrationName": null
  }
} +527369ms

Your database is now in sync with your schema.

@Jolg42 Got it, here’s the new issue 👍

@tiagoernst your issue seems to be different, this issue is about having many migrations, and you only have 2. Also, the issue template helps to get more information in a structured way. A new issue is often the best option in many cases.

Hey @Jolg42 here’s some additional information:

Prisma client: 5.2.0 OS: node:v20.9.0 Database: mysql:8.0.23 Where running: terminal querying mysql container Migration count: 2 Command: migrate dev --skip-generate took ~6min

I can create a new issue but since this one is still open isn’t it still the same issue ?

(EDIT: our model is a bit large ~150 tables & ~1800 columns if that can help)

@rafayeljamalyan @davecarlson

I think it would be interesting if impacted people could share:

  • the Prisma version

  • the OS

  • the database provider

  • is the CLI running close to the database? (e.g. remote or local database)

  • how many migrations files are in the migrations directory

  • the command and time it took from start to finish

    • Note that for a better measurement, --skip-generate is needed to exclude the time spent on Prisma Client generation, like: migrate dev --skip-generate.

Prisma Client (4.15.0 | library) Node v18.16.0 Mac OS Ventura (13.4), M2 MAX with 32GB RAM Amazon RDS MySQL 46 Migrations –skip-generate took 5 minutes.

Gosh, I am just getting to see this.

I doubt if I would be able to recreate this issue. I was still in the development phase when this happened.

Thanks for your assistance.

@arvindell thanks for the issue!

Unfortunately there is quite a lot of operations under the hood that migrate executes.

Your question on the workflow is spot on though as we are currently working on documentation for squashing migrations.