alembic
alembic copied to clipboard
if/when SQLAlchemy provides truncation for naming convention names, need to do that same truncation on the name comparison side
Migrated issue, originally created by Danny Milosavljevic
Hi,
postgresql automatically truncates too-long index names (for the limit see "SELECT max_identifier_length - 1 FROM pg_control_init()") but alembic does not truncate index names in this manner.
That means that if an index name is too long then alembic will always generate a spurious migration where it tries to create the index with the long name and drop the index with the short name.
The bug is not that bad because for cases where the sqlalchemy naming convention generates index names that are too long you can just override it in the model by specifying a non-autogenerated index name ("name=...").
But in the long run it would be nice if alembic would also auto-truncate index names like postgres does.
It is apparently not possible to disable autotruncation in postgresql 9.6.1, so it might be a bit difficult to find these cases.
Michael Bayer (@zzzeek) wrote:
Hi -
I would assume this is arising because you are using the automated naming convention feature. SQLAlchemy itself should not be generating too-long names because it itself truncates names. PG's name truncation should not be taking effect (need details to confirm this is the case).
However, when it does the name comparison of your Python, it is not doing the truncation first to compare to what would be coming back from the database, so that can be adjusted.
However I need details on the above things. Are you using naming conventions, if so what is it, please provide specifics , as well as what the Table / Index metadata in question looks like, I can add a round trip test and add in that dialect-level truncation rules should take effect.
Michael Bayer (@zzzeek) wrote:
or perhaps the truncation isn't taking effect on the SQLAlchemy side for names. This would be a SQLAlchemy bug. If you can please provide specifics we can get it reported there.
Michael Bayer (@zzzeek) wrote:
here's that SQLAlchemy issue already there: https://bitbucket.org/zzzeek/sqlalchemy/issues/3989/warn-error-for-too-long-naming-convention
Changes by Danny Milosavljevic:
- edited description
Changes by Michael Bayer (@zzzeek):
- changed title from "Index name auto-truncation done in postgres but no" to "if/when SQLAlchemy provides truncation for naming "