-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix now() not working for new migrations default value #18845
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
Conversation
|
At least for MySQL, you could have pretty wild defaults such as Instead of keeping a list, I would suggest that if the value of Only escape the value, if it's a |
Yes, this would be ideal and is something I missed when porting code from migrations to cakephp/database. |
|
But would such a change be doable in a patch release? This change at least can be relased in the next patch release IMHO, but the |
But then you should maybe use the stricter approach mark suggested: |
e547501 to
3455264
Compare
Yes, I was also thinking about this today. I don't think we can do the change I proposed in a patch release. However, I would like to include it in 5.3 alongside the other schema system improvements & fixes. How about we merge this as a short term solution, and we can add more scenarios as they come up. I'll work on building a solution for using |
| ['type' => 'datetime', 'null' => false, 'default' => 'now()'], | ||
| '"created_now" DATETIME NOT NULL DEFAULT current_timestamp', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this translation be happening? Is now() not portable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlite doesn't have a now() function like MySQL does.
sqlite> SELECT current_timestamp;
2025-08-24 14:22:32
sqlite> SELECT now();
Parse error: no such function: now
SELECT now();
^--- error here
sqlite> SELECT now;
Parse error: no such column: now
SELECT now;
^--- error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to commit to having a translation for literal values? I would expect that if I use a literal, I get what I provided without the framework changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but then we need some DBMS agnostic way to represent those values which is not a magic string.
I expect a migrations plugin to define my schema once and no matter which DBMS is used behind it, it should create the correct schema (if the features are supported of course)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect a migrations plugin to define my schema once and no matter which DBMS is used behind it, it should create the correct schema (if the features are supported of course)
But the now() function isn't something that is supported by all database vendors. Given that the context of this issue is for literal expressions I don't think we should be providing translations for those literals, as we won't be able to do that in the future when literal support is expanded.
Basically I'm with you that a patch release should never introduce any breaking changes. But the current documentation describes Literal::from() as it used to be
Yeah this was a miss on my part when I was doing the phinx cleanup. The diff in #18858 is pretty minimal and could be merged into 5.x instead of 5.next. That change along with a fix for migrations should get us back to a working state for Literal values more broadly.
Basically I'm with you that a patch release should never introduce any breaking changes. But the current documentation describes I'm using |
With the changes from cakephp/cakephp#18858 these changes should resolve the regressions around `Literal` values raised in cakephp/cakephp#18845
|
I have a similar problem to this, but with When i execute the migration: My config:
|
|
@arthusantiago What version of migrations are you using? |
"cakephp/migrations": "4.7.1", |
@arthusantiago How is that possible with cakephp 5.1? The requirements for 4.7.1 require at least 5.2. Any fixes I'd be able to make should only apply to new code added in 5.2 as well. |
|
With no additional feedback on #18858 I'd like to merge that and the related migrations change so that we can get a fix out sooner. |
|
@markstory |
Ok. That output makes more sense. 👍 |
|
With https://github.com/cakephp/cakephp/pull/18858/files being merged and released with 5.2.7, I'd say wen can close this as the desired behavior can be achieve via using a |
* Fix Literal default values With the changes from cakephp/cakephp#18858 these changes should resolve the regressions around `Literal` values raised in cakephp/cakephp#18845 * Bump cake version to test against QueryExpression fix * Revert "Bump cake version to test against QueryExpression fix" This reverts commit a7ee824.

@nook24 reported in slack, that
doesn't work in the new migrations plugin. It returned
DEFAULT 'now()'which is not valid.Reason behind that is the fact, that we didn't handle those cases separately till now. We only checked for
current_timestampAs far as I have checked in most DBMSs
now()andcurrent_timestampare equal