You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 503958e
Browse filesBrowse the repository at this point in the historyBrowse files
Add support for ALTER COLUMN with SET DEFAULT and DROP DEFAULT (WordPress#555)
Previously, `ALTER TABLE ... ALTER COLUMN ... SET DEFAULT` and `DROP
DEFAULT` succeeded but left the old defaults in place. This PR makes
**new inserts and schema metadata use the changed defaults**, while
preserving existing row values and unrelated column attributes.
For example, after setting an integer column's default from `1` to `5`
and dropping a string column's default of `'x'`, an insert that omits
both columns now uses `5` and `NULL`.
The change also handles the related error and compatibility cases:
- Rejects `NULL` defaults on `NOT NULL` columns and preserves automatic
ID generation.
- Applies `ALTER COLUMN` changes in order with the other `ALTER TABLE`
actions, reports missing tables and columns correctly, and rolls back
failed changes.
- Covers permanent and temporary tables, quoted names, literal and
expression defaults, inserted values, and schema metadata with
regression tests.
`SET DEFAULT (expr)` on an `ON UPDATE CURRENT_TIMESTAMP` column **stops
its automatic update**, because the driver doesn't create the update
trigger for columns with an expression default. Fixing that detection
alone would let the trigger overwrite explicitly written timestamps on
many more tables, so it's fixed together with the trigger in WordPress#554.
Keeping a nullable column without a default after `DROP DEFAULT` is
tracked in WordPress#556.
The existing PDO coding-standard exemption also covers the plugin's
symlinked copy of the driver.
FixesWordPress#553.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **New Features**
* Added support for changing or removing column defaults with `ALTER
TABLE`, including literal and expression defaults. Updated defaults
appear in column metadata and apply to subsequent inserts.
* **Bug Fixes**
* Improved handling and validation of signed numeric and `BIT` defaults.
* Missing tables and columns now return more accurate MySQL-compatible
errors.
* Improved recognition of `ON UPDATE CURRENT_TIMESTAMP` column settings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
0 commit comments