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

Handle AUTOINCREMENT modification detection in revision auto-generation #1224

Open
TheoGoudout opened this issue Apr 20, 2023 · 1 comment
Open
Labels
autogenerate - detection autogenerate - rendering mysql use case not quite a feature and not quite a bug, something we just didn't think of

Comments

@TheoGoudout
Copy link

Describe the use case
Unless I'm mistaken, toggling the autoincrement attribute of a table column is not detected by the revision auto-generation.

Databases / Backends / Drivers targeted
My usecase is for MySQL databases, but I guess it would be nice to have for any DB that supports this feature (although I'm not familiar with which DBs that would be).

Example Use
Migrate from

CREATE TABLE `FOO` (
  `ID` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
);

to

CREATE TABLE `FOO` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`ID`)
);

would generate a difference in a migration script.

Have a nice day!

@TheoGoudout TheoGoudout added requires triage New issue that requires categorization use case not quite a feature and not quite a bug, something we just didn't think of labels Apr 20, 2023
@zzzeek
Copy link
Member

zzzeek commented Apr 20, 2023

this would not be very simple as SQLAlchemy considers this AUTO_INCREMENT as an implicit thing it turns on.

that is

Table("x", m, Column("id", Integer, primary_key=True))

if you generate that on MySQL, it will include AUTO_INCREMENT automatically. only if you had the column in the model like this:

Table("x", m, Column("id", Integer, primary_key=True, autoincrement=False))

does that actually mean "primary key integer column without AUTO_INCREMENT". So I guess what I'm thinking is that it's very unusual you'd have a MySQL table of this nature if it were managed by SQLAlchemy the whole time since people don't really set that flag to False without being very deliberate.

Another problem is that Alembic has no support for autogen of database specific constructs; it seeks to produce migration files that are database agnostic. In this case, I dont think we really have a migration construct that adds this flag alone to a MySQL column. We have a similar issue with ENUM datatypes as PostgreSQL has an elaborate system of types that we also don't autogenerate in an explicit way.

all of this is to say that w/ Alembic's current development profile there's not much chance of something like this happening as we don't even have the API architecture in place to properly support autogen of migrations that are conditional on certain database backends.

@zzzeek zzzeek added autogenerate - detection autogenerate - rendering mysql and removed requires triage New issue that requires categorization labels Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autogenerate - detection autogenerate - rendering mysql use case not quite a feature and not quite a bug, something we just didn't think of
Projects
None yet
Development

No branches or pull requests

2 participants