Skip to content

Add DEFAULT support for CURRENT_DATE, CURRENT_TIME, LOCALTIME, LOCALTIMESTAMP#963

Merged
markstory merged 3 commits into5.xfrom
5.x-current-timestamp
Dec 2, 2025
Merged

Add DEFAULT support for CURRENT_DATE, CURRENT_TIME, LOCALTIME, LOCALTIMESTAMP#963
markstory merged 3 commits into5.xfrom
5.x-current-timestamp

Conversation

@dereuromark
Copy link
Copy Markdown
Member

@dereuromark dereuromark commented Nov 22, 2025

Summary

  • Expand automatic SQL function handling to support more standard SQL datetime defaults without requiring Literal::from()
  • Add CURRENT_DATE support for date columns
  • Add CURRENT_TIME and LOCALTIME support for time columns
  • Add LOCALTIMESTAMP support for datetime/timestamp columns
  • Update documentation with new column type options

Details

SQL Function Valid Column Types
CURRENT_TIMESTAMP datetime, timestamp, time, date
CURRENT_DATE date
CURRENT_TIME time

Dropped (not supported yet also in ORM):

SQL Function Valid Column Types
LOCALTIMESTAMP datetime, timestamp
LOCALTIME time

Each function is only left unquoted when used with appropriate column types. Using them with incompatible types (e.g., CURRENT_DATE on a string column) will quote the value as a literal string.

Usage

// Now works without Literal::from()
$table->addColumn('birth_date', 'date', ['default' => 'CURRENT_DATE']);
$table->addColumn('start_time', 'time', ['default' => 'CURRENT_TIME']);

//Dropped again
//$table->addColumn('created_at', 'datetime', ['default' => 'LOCALTIMESTAMP']);

…IMESTAMP

Expand automatic SQL function handling in getDefaultValueDefinition() to
support more standard SQL datetime functions without requiring Literal::from():

- CURRENT_DATE for date columns
- CURRENT_TIME for time columns
- LOCALTIME for time columns
- LOCALTIMESTAMP for datetime/timestamp columns

Each function is only unquoted when used with appropriate column types.
Using them with incompatible types (e.g., CURRENT_DATE on a string column)
will quote the value as a literal string.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dereuromark
Copy link
Copy Markdown
Member Author

I am also fine not supporting LOCALTIMESTAMP/LOCALTIME in favor of the other 3, if we want to keep it simpler.

@markstory
Copy link
Copy Markdown
Member

I am also fine not supporting LOCALTIMESTAMP/LOCALTIME in favor of the other 3, if we want to keep it simpler.

I don't think we have support for LOCALTIME/LOCALTIMESTAMP in the reflection APIs. That will make snapshots lossy.

@dereuromark
Copy link
Copy Markdown
Member Author

I guess you are also not interested in supporting them correct? Otherwise we could fix up core support first here.

@markstory
Copy link
Copy Markdown
Member

I guess you are also not interested in supporting them correct? Otherwise we could fix up core support first here.

We've never had anyone ask for support for them. We can always add support in the future when folks need it.

@dereuromark
Copy link
Copy Markdown
Member Author

if no one asked for it yet, maybe we dont need to widen the scope now.
I will remove those then, and simplify this PR.

@markstory markstory merged commit 7bdc30e into 5.x Dec 2, 2025
13 checks passed
@markstory markstory deleted the 5.x-current-timestamp branch December 2, 2025 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants