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
implement type detection change for MySQL ENUM #779
Comments
Looking at this further (for mysql), I realised that if the number of enum values is the same, then changes in the list of possible enum values are detected - but, if you add an enum item, they are not. That's because in if (
len(meta_params.args) == len(inspected_params.args)
and meta_params.args != inspected_params.args
):
return False i.e. if the length of the args list is different, then we ignore the args values and detect no change. Detecting a change whenever the length of the args lists are different would make sense, but I'm sure it produces tons of false positives - I already saw that myself with spurious As a workaround I tried adding this: if (
meta_params.token0 == 'enum'
and len(meta_params.args) != len(inspected_params.args)
):
return False This does actually work for my experiment - I added an item to my enum, and the correct migration script was produced. I don't imagine this is the right answer in general though. Maybe we can always detect a change in num args as a change, but filter out false positives like the |
enum is a special case, so I would not rely upon the logic added as part of #605 for this datatype. as things worked previously, a new compare_type() method should be restored to https://github.com/sqlalchemy/alembic/blob/master/alembic/ddl/mysql.py#L141 which accommodates for ENUM explicitly before calling the superclass method. |
that's essentially what your workaround is doing. |
I am still having this problem as well in MySQL, using But in contrast, if I define a new column using the I also confirmed that when reflecting, the column's type is |
Here is how I solved it: def my_compare_type(context, inspected_column, metadata_column, inspected_type, metadata_type):
# return False if the metadata_type is the same as the inspected_type
# or None to allow the default implementation to compare these
# types. a return value of True means the two types do not
# match and should result in a type change operation.
if isinstance(inspected_type, sqlalchemy.Enum) and isinstance(metadata_type, sqlalchemy.Enum):
inspected_enum_values = set(inspected_type.enums)
metadata_enum_values = set(metadata_type.enums)
return inspected_enum_values != metadata_enum_values
return None ...and then in context configuration: context.configure(
...
compare_type=my_compare_type,
) Just edit in env.py! |
This issue also applies to postgres. But the custom (In the case of native enum, it never actually emits a statement to update the type definition; in non-native varchar+CHECK enums, it correctly updates the length of the field and emits a |
this refers to native enum. per #329 (comment) this is not being detected right now and as of #605 we do generally compare arguments.
The text was updated successfully, but these errors were encountered: