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

me: fix regression in enum column type diffing #3374

Merged
merged 1 commit into from Nov 9, 2022

Conversation

tomhoule
Copy link
Contributor

@tomhoule tomhoule commented Nov 9, 2022

This regression was reported by users in
prisma/prisma#16180

It was introduced on b6400f1 by the
same change that caused the other regression that was fixed in
eb39236.

Symptoms: enum migrations became non-idempotent in many cases, depending
on the ordering of the migrations in the Prisma schema.

In that refactoring, we started storing enum ids instead of enum names
in ColumnTypeFamily::Enum(_). That makes the ColumntypeFamily type
smaller, easier to deal with with regards to ownership (EnumId is
Copy), and ready for multi-schema, because the name can be ambiguous
and does not carry schema information, whereas the EnumId does. But
more relevant to this commit: it makes comparing two
ColumnTypeFamily inaccurate when the types come from two different
schemas
, like in sql_schema_differ.

That in turn changed the signature of column_type_family_as_enum(),
leading to the differ comparing enum ids instead of enum names, which
directly causes the false positives in diffing, because the same enum
has a different ID in each of the two schemas. The code that caused the
regression does not appear in b6400f1,
it uses code that was changed there.

This is also a problem with the generated implementation of PartialEq
for ColumnTypeFamily. Since it would be a larger refactoring, we only
deal with this where relevant (sql_schema_differ) and leave removing the
dangerous PartialEq implementation to another PR. This is the issue:
#3373.

How could this have been caught?

  • Tests that check that migrations are idempotent with multiple enums,
    all used in model columns not defined in alphabetical order (sad but true).
    • This chimes with the theme of us not testing with large enough
      Prisma Schemas.
  • migrations-ci could have caught this. We are neglecting it at the
    moment.

This regression was reported by users in
prisma/prisma#16180

It was introduced on b6400f1 by the
same change that caused the _other_ regression that was fixed in
eb39236.

Symptoms: enum migrations became non-idempotent in many cases, depending
on the ordering of the migrations in the Prisma schema.

In that refactoring, we started storing enum ids instead of enum names
in `ColumnTypeFamily::Enum(_)`. That makes the `ColumntypeFamily` type
smaller, easier to deal with with regards to ownership (`EnumId` is
`Copy`), and ready for multi-schema, because the name can be ambiguous
and does not carry schema information, whereas the `EnumId` does. But
more relevant to this commit: it makes comparing two
`ColumnTypeFamily` inaccurate _when the types come from two different
schemas_, like in sql_schema_differ.

That in turn changed the signature of `column_type_family_as_enum()`,
leading to the differ comparing enum ids instead of enum names, which
directly causes the false positives in diffing, because the same enum
has a different ID in each of the two schemas. The code that caused the
regression does not appear in b6400f1,
it uses code that was changed there.

This is also a problem with the generated implementation of PartialEq
for ColumnTypeFamily. Since it would be a larger refactoring, we only
deal with this where relevant (sql_schema_differ) and leave removing the
dangerous PartialEq implementation to another PR. This is the issue:
#3373.

How could this have been caught?

- Tests that check that migrations are idempotent with multiple enums,
  all used in model columns _not defined in alphabetical order_ (sad but true).
  - This chimes with the theme of us not testing with large enough
    Prisma schemas.
- migrations-ci could have caught this. We are neglecting it at the
  moment.
@tomhoule tomhoule force-pushed the me/fix-enum-migrations-regression-without-map branch from 45be4e0 to e23c254 Compare November 9, 2022 13:37
@tomhoule tomhoule added this to the 4.7.0 milestone Nov 9, 2022
@tomhoule tomhoule marked this pull request as ready for review November 9, 2022 13:40
@tomhoule tomhoule requested a review from a team as a code owner November 9, 2022 13:40
Copy link
Contributor

@eviefp eviefp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tomhoule tomhoule merged commit 5c57682 into main Nov 9, 2022
@tomhoule tomhoule deleted the me/fix-enum-migrations-regression-without-map branch November 9, 2022 14:42
tomhoule added a commit that referenced this pull request Nov 9, 2022
This regression was reported by users in
prisma/prisma#16180

It was introduced on b6400f1 by the
same change that caused the _other_ regression that was fixed in
eb39236.

Symptoms: enum migrations became non-idempotent in many cases, depending
on the ordering of the migrations in the Prisma schema.

In that refactoring, we started storing enum ids instead of enum names
in `ColumnTypeFamily::Enum(_)`. That makes the `ColumntypeFamily` type
smaller, easier to deal with with regards to ownership (`EnumId` is
`Copy`), and ready for multi-schema, because the name can be ambiguous
and does not carry schema information, whereas the `EnumId` does. But
more relevant to this commit: it makes comparing two
`ColumnTypeFamily` inaccurate _when the types come from two different
schemas_, like in sql_schema_differ.

That in turn changed the signature of `column_type_family_as_enum()`,
leading to the differ comparing enum ids instead of enum names, which
directly causes the false positives in diffing, because the same enum
has a different ID in each of the two schemas. The code that caused the
regression does not appear in b6400f1,
it uses code that was changed there.

This is also a problem with the generated implementation of PartialEq
for ColumnTypeFamily. Since it would be a larger refactoring, we only
deal with this where relevant (sql_schema_differ) and leave removing the
dangerous PartialEq implementation to another PR. This is the issue:
#3373.

How could this have been caught?

- Tests that check that migrations are idempotent with multiple enums,
  all used in model columns _not defined in alphabetical order_ (sad but true).
  - This chimes with the theme of us not testing with large enough
    Prisma schemas.
- migrations-ci could have caught this. We are neglecting it at the
  moment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants