Opened 10 years ago
Last modified 5 years ago
#28591 new defect (bug)
dbDelta Non-literal DEFAULT not working (CURRENT_TIMESTAMP)
Reported by: | sc0ttkclark | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Database | Keywords: | needs-patch |
Focuses: | Cc: |
Description
Using dbDelta and any internal SQL values like CURRENT_TIMESTAMP won't work because dbDelta matches based on this regex:
"| DEFAULT '(.*?)'|i"
The block current looks like this:
if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) { $default_value = $matches[1]; if ($tablefield->Default != $default_value) { // Add a query to change the column's default value $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'"; $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; } }
I'm not sure what the best solution is for this, but perhaps it should be:
- Check if there is a default to change, if there is -- store default alter query, don't add to $cqueries[] yet
- Check if there is a field type change OR a default non-literal found, if there is -- use this CHANGE COLUMN query instead of the 'default' changing query in point 1
Does that sound like a good solution here?
Change History (3)
Note: See
TracTickets for help on using
tickets.
Here's an idea for at line 1672 in upgrade.php, but it can be further improved for sure.