This change is the culprit,

https://github.com/zzzeek/alembic/commit/4cdb25bf5d70e6e8a789c75c59a2a908433674ce#diff-e9d21bbd0f4be415139b75917420ad1c

I've a few auto-generated tables, that are one-to-one mappings with an 
external data feed.  For any fields that have indexes set on them, the 
mapping messes up, and thinks there's always a change.

Consider the very simple class,


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    registrationNumber = db.Column(db.Integer, index=True)


The index for "registrationNumber" is named "ix_user_registrationNumber".

*But* in compare.py, when it's running through the added, changed, and 
removed indexes, it compares "metadata_names" with "conn_names".

*Before* this change, metadata_names used c.name as its "key", same as 
conn_names, but *after* this change, metadata_names use 
c.md_name_to_sql_name(autogen_context), 

whereas conn_names continues to use the "simple" c.name.

I'd say for the majority of use cases, where field names are pep8 standard, 
and lower case with underscores, instead of camel case, there's no issue, 
but when you have a situation like "registrationNumber" here, when you look 
at what happens inside that md_name_to_sql_name,

*Eventually*, we end up in,

https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/sql/compiler.py#L3026

The check for "requires_quotes" checks a number of things, but eventually 
checks if the lowercase version of the field is equal to the field name, 
i.e. in this case, is "ix_user_registrationNumber" equal to 
"ix_user_registrationnumber" which is obviously false, and that check then 
quotes that field.  This means, the key for the metadata_name turns in to 
"`ix_user_registrationNumber`", quoted, with ticks, but conn_name is still 
"ix_user_registrationNumber", not quoted, no ticks.

The result of this is that, at every attempted migrate, you get

INFO  [alembic.autogenerate.compare] Detected added index 
'ix_user_registrationNumber' on '['registrationNumber']'
INFO  [alembic.autogenerate.compare] Detected removed index 
'ix_user_registrationNumber' on 'user'

And no matter how many times you run an upgrade, you still get that result.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to