Skip to content

Conversation

@dereuromark
Copy link
Member

Resolves cakephp/phinx#1891

When setting 'CURRENT_TIMESTAMP' as a default value on non-datetime columns (like VARCHAR/TEXT), it was not being quoted properly, causing SQL errors.
The logic was inverted - it would only quote strings that DON'T start with CURRENT_TIMESTAMP, when it should only skip quoting for datetime-related columns.

with the buggy code, these scenarios would FAIL:

  1. ❌ 'CURRENT_TIMESTAMP' on STRING column → would output DEFAULT CURRENT_TIMESTAMP (unquoted - invalid SQL)
  2. ❌ 'CURRENT_TIMESTAMP' on TEXT column → would output DEFAULT CURRENT_TIMESTAMP (unquoted - invalid SQL)
  3. ❌ 'CURRENT_TIMESTAMP' on CHAR column → would output DEFAULT CURRENT_TIMESTAMP (unquoted - invalid SQL)
  4. ❌ 'CURRENT_TIMESTAMP' on INTEGER column → would output DEFAULT CURRENT_TIMESTAMP (unquoted - invalid SQL)

The Fix:
Only skip quoting CURRENT_TIMESTAMP for datetime-related column types.
For other types (like string), it should be quoted as a literal string value.

@dereuromark dereuromark added this to the 4.x (CakePHP 5) milestone Oct 19, 2025
@markstory markstory merged commit efe451a into 4.x Oct 19, 2025
13 checks passed
@markstory markstory deleted the 4.x-timestamp branch October 19, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CURRENT_TIMESTAMP not quoted even for non-datetime columns

3 participants