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

Invalid db pull / db push flow #13381

Closed
janpio opened this issue May 15, 2022 · 2 comments · Fixed by prisma/prisma-engines#2972 or prisma/prisma-engines#2977
Closed

Invalid db pull / db push flow #13381

janpio opened this issue May 15, 2022 · 2 comments · Fixed by prisma/prisma-engines#2972 or prisma/prisma-engines#2977
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: mysql topic: prisma db pull CLI: prisma db pull topic: prisma db push CLI: prisma db push
Milestone

Comments

@janpio
Copy link
Member

janpio commented May 15, 2022

SQL:

CREATE TABLE `cm_linkprw` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `video` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

leads to invalid:

enum cm_linkprw_video {
  0 @map("0")
  1 @map("1")
}

so modified to:

enum cm_linkprw_video {
  is_false  @map("0")
  is_true   @map("1")
}

and adapted main model as well.

Problem is that another db pull changes that to this:

model cm_linkprw {
  ID          Int              @id @default(autoincrement()) @db.UnsignedInt
  postId      Int              @db.UnsignedInt
  url         String           @db.VarChar(150)
  video       cm_linkprw_video @default(dbgenerated("0"))
}

which when migrated then leads to:

Datasource "db": MySQL database "pabau" at "localhost:3307"
Error: Invalid default value for 'video'
   0: sql_migration_connector::apply_migration::apply_migration
             at migration-engine\connectors\sql-migration-connector\src\apply_migration.rs:9
   1: migration_core::state::SchemaPush
             at migration-engine\core\src\state.rs:347

error Command failed with exit code 1.

Changing the weird default back to:

video       cm_linkprw_video @default(is_false)

is undone on each db pull

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. topic: mysql team/schema Issue for team Schema. topic: prisma db push CLI: prisma db push topic: prisma db pull CLI: prisma db pull labels May 15, 2022
@pimeys pimeys self-assigned this Jun 9, 2022
@Jolg42 Jolg42 added this to the 4.0.x milestone Jun 10, 2022
@janpio
Copy link
Member Author

janpio commented Jun 10, 2022

The SQL of the migration is actually only invalid as there are single quotes missing when running db pull. This is valid and migrates correctly:

model cm_linkprw {
  ID    Int              @id @default(autoincrement()) @db.UnsignedInt
  video cm_linkprw_video @default(dbgenerated("'0'"))
}

enum cm_linkprw_video {
  is_false @map("0")
  is_true @map("1")
}

Follow up issue about this broken Introspection: #13754

@janpio
Copy link
Member Author

janpio commented Jun 10, 2022

I could still confirm the problem described in the issue (that the manually changed @default is undone again on db pull).

To the fix that was done in this PR (which I read as: "Keep valid renamed enum values as field defaults on Re-Introspection"), I think it is missing the warning message we usually add in these cases. When I run the recent dev for the above example, I get this only:

*** WARNING ***

These enum values were enriched with `@map` information taken from the previous Prisma schema.
- Enum "cm_linkprw_video"
- Enum "cm_linkprw_video"

I suggest we add another warning for the kept is_false value of cm_linkprw.video:

These fields of enum types were enriched with `@default` information taken from the previous Prisma schema:
- Field "cm_linkprw_video.video", value "is_false"

Or something like that.

@janpio janpio reopened this Jun 10, 2022
@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jun 10, 2022
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. topic: mysql topic: prisma db pull CLI: prisma db pull topic: prisma db push CLI: prisma db push
Projects
None yet
3 participants