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

Migration is created for the @default(dbgenerated(...)) value on DateTime although already migrated #24240

Open
MaximTovstashev opened this issue May 18, 2024 · 1 comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: endless migrations topic: migrate topic: postgresql topic: prisma migrate dev CLI: prisma migrate dev

Comments

@MaximTovstashev
Copy link

Bug description

When new table is created with @default(dbgenerated("NOW() + interval '1 day'")) @db.Timestamp(6) column and the migration is applied, next run of npx prisma migrate dev requests to create a new migration for the same column.

How to reproduce

  1. For the postgres database create a new table with field like
expire_at  DateTime  @default(dbgenerated("NOW() + interval '1 day'")) @db.Timestamp(6)
  1. Create an apply a migration. Migration file will contain the correct definition for the column:
"expire_at" TIMESTAMP(6) NOT NULL DEFAULT NOW() + interval '1 day',
  1. Run npx prisma migrate dev without changing anything else
  2. You will be prompted to create a new migration. Give it a name and confirm
  3. New migration will be created, containing a single clause
ALTER TABLE "employee_accounts_transactions" ALTER COLUMN "expire_at" SET DEFAULT NOW() + interval '1 day';
  1. Repeat steps 3 and 4 — new migration with the same content of step 5 will be created

Expected behavior

No new migrations are created after the initial one

Prisma information

model employee_accounts_transactions {
    id                                  Int                                     @id @default(autoincrement())
    amount                              Decimal                                 @db.Decimal(10, 2)
    reason                              Json
    initiator                           Json

    created_at                          DateTime                                @default(now()) @db.Timestamp(6)
    updated_at                          DateTime?                               @updatedAt @db.Timestamp(6)
    expire_at                           DateTime                                @default(dbgenerated("NOW() + interval '1 day'")) @db.Timestamp(6)
}
// Add your code using Prisma Client

Environment & setup

  • OS: ubuntu 22
  • Database: PostgreSQL
  • Node.js version: v20.10.0

Prisma Version

prisma                  : 5.14.0
@prisma/client          : 5.14.0
Computed binaryTarget   : debian-openssl-1.0.x
Operating System        : linux
Architecture            : x64
Node.js                 : v20.10.0
Query Engine (Node-API) : libquery-engine e9771e62de70f79a5e1c604a2d7c8e2a0a874b48 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.0.x.so.node)
Schema Engine           : schema-engine-cli e9771e62de70f79a5e1c604a2d7c8e2a0a874b48 (at node_modules/@prisma/engines/schema-engine-debian-openssl-1.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48
Default Engines Hash    : e9771e62de70f79a5e1c604a2d7c8e2a0a874b48
Studio                  : 0.500.0

@MaximTovstashev MaximTovstashev added the kind/bug A reported bug. label May 18, 2024
@laplab laplab added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: migrate team/schema Issue for team Schema. topic: postgresql labels May 20, 2024
@janpio
Copy link
Member

janpio commented May 21, 2024

What happens to your Prisma schema when you run prisma db pull - does it update the expire_at definition, and then also fix the migration problem?

@janpio janpio changed the title Migration is created for the default dbgenerated value on DateTime Migration is created for the @default(dbgenerated(...)) value on DateTime although already migrated May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: endless migrations topic: migrate topic: postgresql topic: prisma migrate dev CLI: prisma migrate dev
Projects
None yet
Development

No branches or pull requests

3 participants