mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-09-28 13:50:55 +02:00
Rewrite default '0000-00-00 00:00:00' to now()
The current rewriting changes "default '0000-00-00 00:00:00'" when it appears in CREATE TABLE statements, but does not handle the case that a column default value is modified. This results in errors such as the following during schema upgrade: Error running : ALTER TABLE wp_users ALTER COLUMN user_registered SET DEFAULT '0000-00-00 00:00:00' ---- converted to ---- ALTER TABLE wp_users ALTER COLUMN user_registered SET DEFAULT '0000-00-00 00:00:00' ----> ERROR: date/time field value out of range: "0000-00-00 00:00:00" Apply the conversion to ALTER TABLE statements as well. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
'unsigned' => '',
|
'unsigned' => '',
|
||||||
'gmt datetime NOT NULL default \'0000-00-00 00:00:00\'' => 'gmt timestamp NOT NULL DEFAULT timezone(\'gmt\'::text, now())',
|
'gmt datetime NOT NULL default \'0000-00-00 00:00:00\'' => 'gmt timestamp NOT NULL DEFAULT timezone(\'gmt\'::text, now())',
|
||||||
'default \'0000-00-00 00:00:00\'' => 'DEFAULT now()',
|
'default \'0000-00-00 00:00:00\'' => 'DEFAULT now()',
|
||||||
|
'\'0000-00-00 00:00:00\'' => 'now()',
|
||||||
'datetime' => 'timestamp',
|
'datetime' => 'timestamp',
|
||||||
'DEFAULT CHARACTER SET utf8' => '',
|
'DEFAULT CHARACTER SET utf8' => '',
|
||||||
|
|
||||||
@@ -86,6 +87,13 @@ WHERE bc.oid = i.indrelid
|
|||||||
$newq .= ";ALTER TABLE $table RENAME COLUMN $col TO $newcol;";
|
$newq .= ";ALTER TABLE $table RENAME COLUMN $col TO $newcol;";
|
||||||
$sql = $newq;
|
$sql = $newq;
|
||||||
}
|
}
|
||||||
|
$pattern = '/ALTER TABLE\s+(\w+)\s+ALTER COLUMN\s+/';
|
||||||
|
if( 1 === preg_match( $pattern, $sql))
|
||||||
|
{
|
||||||
|
// Translate default values
|
||||||
|
$sql = str_replace(
|
||||||
|
array_keys($GLOBALS['pg4wp_ttr']), array_values($GLOBALS['pg4wp_ttr']), $sql);
|
||||||
|
}
|
||||||
$pattern = '/ALTER TABLE\s+(\w+)\s+ADD COLUMN\s+([^\s]+)\s+([^ ]+)( unsigned|)\s+(NOT NULL|)\s*(default (.+)|)/';
|
$pattern = '/ALTER TABLE\s+(\w+)\s+ADD COLUMN\s+([^\s]+)\s+([^ ]+)( unsigned|)\s+(NOT NULL|)\s*(default (.+)|)/';
|
||||||
if( 1 === preg_match( $pattern, $sql, $matches))
|
if( 1 === preg_match( $pattern, $sql, $matches))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user