sqlalchemy / alembic Public
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
Specify column position for add column in batch mode #640
Comments
Hi there - I re-read this a few times and it's not clear if you're looking for MySQL's directive, which is easy to add, or you are looking for a general utility to rewrite the columns of a table in a different order specific to batch. the former is easy, the latter I don't know if i'd want to add that and it seems like more of a recipe thing. |
Closer to the latter. MySQL is the only db that support this syntax and has an option to specify column position. In other dbs you have to work this around with pretty much the same pattern what the batch |
Here's the way I'd want to do it, however some internal mechanics of the insert from select are causing it to fail and I don't have the resources to figure out why right now. If someone has the resources to work on this, the general idea is to use topological sort and to reorder the columns when we're ready to make the table.
|
Not really sure how this commented out piece looked like
but my guess is that when trying to set |
yes that was an assignment. the batch.py module is a little tricky, I don't work on it much and usually have to re-familiarize for awhile when something needs to change. Also the general subject of dependency sorting requires some getting used to. I'm not totally sure it's feasible how I'm proposing the feature; one can specify any combination of columns that suggests part of the ordering, but then this might imply that it's not possible to maintain the order of the rest of the columns, so not really sure. it is pretty straightforward to get it to work for new columns being added in however. I can look at this more directly after the holidays. |
specifically it was this:
this is based on the guess that the "insert from select" needs the column ordering for the old and new tables at the same time but I'm not sure if that's correct. |
This is where it fails
but it my opinion you don't need the |
@zzzeek did you have a chance to think about my last comment? |
not really I was hoping someone had time to look into making a working version of this |
Marcin Szymanski has proposed a fix for this issue in the master branch: Support explicit column ordering in batch mode https://gerrit.sqlalchemy.org/1698 |
I'd like to hear your opinion on possibility of setting the position of a column added in a batch migration (something like
FIRST
orAFTER <COLUMN>
in mysql). It could work through an extra parameter in batchadd_column
My initial estimate is that changes would be required here: https://github.com/sqlalchemy/alembic/blob/master/alembic/operations/batch.py#L374 and in
OrderedDict
in sqlalchemy to support insertsThe text was updated successfully, but these errors were encountered: