Skip to content

Fix ColumnDefinitionParser to parse unquoted DEFAULT NULL as SQL NULL - #1202

Open
Lugat wants to merge 3 commits into
yiisoft:masterfrom
Lugat:fix-default-null-definition
Open

Lugat wants to merge 3 commits into
yiisoft:masterfrom
Lugat:fix-default-null-definition

Conversation

@Lugat

@Lugat Lugat commented Oct 1, 2026

Copy link
Copy Markdown

As discussed in yiisoft/db-mysql#485: an unquoted NULL after DEFAULT was stored as defaultValueRaw = 'NULL'. The MySQL ColumnFactory typecasts it by column type, so int DEFAULT NULL was created as DEFAULT 0. This breaks the yiisoft/queue-db migration: messages are never reserved because reserved_at IS NULL never matches.

String defaults are always quoted in a column definition, so an unquoted NULL can only be SQL NULL. It is now parsed as defaultValueRaw = null. Schema reading from information_schema is not affected, so varchar DEFAULT 'NULL' keeps working.

Checked on MySQL 8.0: int DEFAULT NULL → DEFAULT NULL (was DEFAULT 0); int DEFAULT 5 and varchar(10) DEFAULT 'NULL' are unchanged.

Q A
Is bugfix? ✔️
New feature? ❌
Breaks BC? ❌
Fixed issues yiisoft/db-mysql#485

String defaults are always quoted in a column definition, so an unquoted
NULL can only be SQL NULL. Previously it was stored as defaultValueRaw
'NULL' and the MySQL column factory typecast it to 0 for integer columns
(e.g. 'int DEFAULT NULL' was created as DEFAULT 0).

See yiisoft/db-mysql#485
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.76%. Comparing base (2d126ae) to head (fc4fece).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1202      +/-   ##
============================================
+ Coverage     98.63%   98.76%   +0.13%     
- Complexity     1653     1655       +2     
============================================
  Files           123      123              
  Lines          4309     4305       -4     
============================================
+ Hits           4250     4252       +2     
+ Misses           59       53       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread CHANGELOG.md Outdated
@vjik
vjik requested a review from a team October 1, 2026 09:22
@vjik vjik added the status:code review The pull request needs review. label Oct 1, 2026

@Tigrov Tigrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/Syntax/ColumnDefinitionParser.php Outdated
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
Co-authored-by: Sergei Tigrov <rrr-r@ya.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants