-
-
Notifications
You must be signed in to change notification settings - Fork 284
Invalid SQL is generated when attempting to change server default to CURRENT_TIMESTAMP #564
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
Comments
we don't have explicit support for MySQL's "ON UPDATE" clause right now, this is in SQLAlchemy as sqlalchemy/sqlalchemy#4652 where we will add a mysql_on_update and we also welcome pull requests in this regard, for the Alembic side there would also be a mysql_on_update parameter consumed by the The "CHANGE" syntax is part of the MySQL Alembic dialect right now however it only takes effect when the column's name is changing. If you add "name='warehouse_last_update'" to your operation it might emit what you want here, please try that. additionally, need to know the scope of the syntax here, can you please share exact MySQL / MariaDB version in use, additionally can you confirm that without the "ON UPDATE" part, the existing ALTER TABLE syntax for change of server defaut still works ? I'm sort of guessing this is MySQL 8 where they have changed all kinds of syntaxes. |
"name='warehouse_last_update'" worked. Thank you! I'm actually working with both MySQL 5.5.59 and 8.0.16. The results are the same on both. |
For more expedient confirmation of op functionality, start building generalized backend fixtures for ops. Add basic round trip tests for alter column, obviously disabled on SQLite. Ensure this passes for the full span of MySQL, Oracle, SQL Server on CI (PG is fine). Next we can begin adding tests for all the MySQL issues that are coming up such as #564, where regular ALTER COLUMN is not consistently implemented based on datatypes etc. Change-Id: I00ef174aa791ce7baeb764c5915591cd095deae0
mariadb supports: ALTER TABLE x ALTER COLUMN colname SET DEFAULT CURRENT_TIMESTAMP MySQL does not. will now try the CHANGE syntax, and see if MariaDB supports that, I bet it doesn't and we have to switch based on mysql / mariadb. |
so you can use CHANGE for all server default changes on both DBs. But I'm not able to find any reasoning for what is different and I don't think I'm going to do it that way, because I bet it does something very different internally like lock the table more aggressively, or something like that. but nobody knows. so at the moment leaning towards regexp for CURRENT_TIMESTAMP / NOW w datetime column only. |
OK "ON UPDATE" is even bundled into how we reflect the default on MySQL in SQLAlchemy right now, that makes sqlalchemy/sqlalchemy#4652 a lot more weird |
Mike Bayer has proposed a fix for this issue in the master branch: Use CHANGE COLUMN for MySQL / MariaDB DateTime server default change https://gerrit.sqlalchemy.org/1277 |
Both |
Beginning with 5.6, there's support for online DDL and beginning with 8.0 there's support for atomic DLL, though at the moment I don't have much experience with either. When I do, I may make some suggestions for making safer, non-blocking DDL statements. I've also been working on a heuristic for arranging operations when using |
well for this issue it's between ALTER COLUMN and CHANGE COLUMN so I have it doing the CHANGE syntax based on a conservative check only. |
emits this:
...which is invalid.
This would be syntactically valid, but still fail:
This seems to be the only valid way:
I understand that in older versions of MySQL simply making a TIMESTAMP column NOT NULL would have the same effect, but newer versions MySQL need that default clause in order to have an auto-initializing/updating timestamp column.
The text was updated successfully, but these errors were encountered: