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

Prisma drops and recreates enum array field when running migrate even if the field has not changed #22456

Open
devunt opened this issue Dec 18, 2023 · 5 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine tech/engines Issue for tech Engines. topic: enum "type"/block `enum` topic: migrate topic: scalar list []

Comments

@devunt
Copy link

devunt commented Dec 18, 2023

Bug description

Running prisma migrate dev always results in re-creating enum array field, even after applying suggested changes (which was re-creating the field)

$ prisma migrate diff --from-schema-datamodel ./prisma/schema.prisma --to-schema-datasource ./prisma/schema.prisma

[*] Changed the `posts` table
  [*] Column `content_filters` would be dropped and recreated (type changed)

How to reproduce

  1. Run prisma migrate dev

Expected behavior

No difference is reported.

Prisma information

model Post {
  id                  String        @id
  ...
  contentFilters         ContentFilterCategory[] @map("content_filters")
  ...

  @@map("posts")
}

enum ContentFilterCategory {
  ADULT
  ...
  OTHER

  @@map("_content_filter_category")
}

Environment & setup

  • OS: macOS 14.2
  • Database: PostgreSQL 15.4
  • Node.js version: v20.10.0

Prisma Version

prisma                  : 5.7.0
@prisma/client          : 5.7.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v20.10.0
Query Engine (Node-API) : libquery-engine 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at ../../node_modules/.pnpm/@prisma+engines@5.7.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at ../../node_modules/.pnpm/@prisma+engines@5.7.0/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.7.0-41.79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Default Engines Hash    : 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Studio                  : 0.495.0
Preview Features        : metrics, tracing
@devunt devunt added the kind/bug A reported bug. label Dec 18, 2023
@janpio

This comment was marked as outdated.

@devunt

This comment was marked as outdated.

@devunt devunt changed the title Regression: Prisma 5.7.0 drops and recreates enum array field when running migrate even if the field has not changed Prisma 5.7.0 drops and recreates enum array field when running migrate even if the field has not changed Dec 19, 2023
@devunt
Copy link
Author

devunt commented Dec 19, 2023

After further investigation, it appears that if I change @@map("_content_filter_action") on enum to @@map("content_filter_action"), the issue is gone. Which seems the starting underscore of the mapped name is causing the issue.

@miguelff
Copy link
Contributor

Hey @devunt _content_filter_action seems to be a different string than that initially reported. Mind sending us a failing and a non-failing schema, So we don't introduce noise in the reproduction? Thank you.

@miguelff miguelff added topic: migrate tech/engines Issue for tech Engines. team/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Dec 20, 2023
@janpio janpio added topic: enum "type"/block `enum` topic: scalar list [] labels Feb 16, 2024
@janpio janpio changed the title Prisma 5.7.0 drops and recreates enum array field when running migrate even if the field has not changed Prisma drops and recreates enum array field when running migrate even if the field has not changed Feb 16, 2024
@SevInf SevInf self-assigned this Mar 1, 2024
@SevInf SevInf added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Mar 1, 2024
@SevInf
Copy link
Contributor

SevInf commented Mar 1, 2024

Reproduced on latest main (5.11.0-dev), internal link.

To reproduce, run prisma migrate dev multiple times. Each migration after the first one will re-create the column and DB would never be reproved as "already in sync". For it to work, you need both @@map("_something") for and the field on the model to be a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine tech/engines Issue for tech Engines. topic: enum "type"/block `enum` topic: migrate topic: scalar list []
Projects
None yet
Development

No branches or pull requests

4 participants