question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration doesn't sync with Database

See original GitHub issue

Bug description

I have been having an issue with the behavior of the @updatedAt, see: Enhance @updatedAt Migration output DDL #7724

Based on a conversation there, I tried alternative solution that looked promising. Basically, using the @default(dbgenerated("CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)")) as a temporary workaround. I know this is a poor use of this feature, but the existing issue is truly becoming a risky problem.

It turns out that it generates the correct SQL, and will solve my problem.

However, it has the side effect of never syncing with the Database. ie: If another migration is run after successfully migrating with this syntax, it just keeps creating a new Migration with all of the same identical changes.

According to your support person, this should still be considered a bug, as it should identify that no changes have been made.

How to reproduce

Change schema

From:

updatedAt           DateTime            @updatedAt

To:

updatedAt           DateTime            @default(dbgenerated("CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"))

Then run

$ npx prisma migrate dev --create-only
$ npx prisma migrate dev

Then run

$ npx prisma migrate dev --create-only
$ npx prisma migrate dev

Expected behavior

Generates

-- AlterTable
ALTER TABLE `SomeTable ` MODIFY `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3);

One time before actually running the Migration. Changes are made to the database when the Migration is run. Additional migrations indicate no changes, and don’t create any migration files.

Prisma information

Old Table Structure

model SomeTable {
  id                  Int                 @unique
  createdAt           DateTime            @default(now())
  updatedAt           DateTime            @updatedAt
  deletedAt           DateTime?
}

Updated Table Structure

model SomeTable {
  id                  Int                 @unique
  createdAt           DateTime            @default(now())
  updatedAt           DateTime            @default(dbgenerated("CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"))
  deletedAt           DateTime?
}

Environment & setup

OS: Windows 10 Database: MySQL 5.7 Node: v14.15.3 npm/npx: 6.14.9

Prisma Version

prisma                  : 3.7.0
@prisma/client          : 3.7.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 8746e055198f517658c08a0c426c7eec87f5a85f
Studio                  : 0.445.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rojer95commented, Mar 30, 2022

Your problem is similar, but different enough to justify its own issue. Can you please create one @rojer95 and provide all the information the issue template asks for? Thanks.

#12574

0reactions
janpiocommented, Mar 30, 2022

Your problem is similar, but different enough to justify its own issue. Can you please create one @rojer95 and provide all the information the issue template asks for? Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add-migration does not work, database out of sync
I've managed somehow to get my databases out of sync. I'm using the code-first approach in building this MVC 4 C#.
Read more >
Troubleshooting migration tasks in AWS Database Migration ...
To migrate secondary objects from your database, use the database's native tools if you are migrating to the same database engine as your...
Read more >
Diagnose issues for MySQL | Database Migration Service
Migration from a managed database (Amazon RDS/Aurora) doesn't start. ... Error Message: Unable to connect to source database server. Database Migration ...
Read more >
Migration troubleshooting in development - Prisma
This guide does not apply for MongoDB. Instead of migrate dev ... Your database and migration history are now in sync, including your...
Read more >
Add-Migration does not detect the change for Entity Framwork ...
It seems that the Entity Framework and the database is out of sync and I would need to run the Add-Migration and Update...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found