If the non-capturing group which contains the last two capture groups of
the expression is not matched, the indexes are not defined in the match
result, causing a warning. Avoid this using isset() before access.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
The flash-album-gallery plugin defines columns using the tinyint type
without a display width. Convert this to smallint.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Data types are not case-sensitive, and the current data type conversion
assumes that the types are all lower-case. Although this is currently
the case for most (all?) of the Wordpress core, it is not the case for
all extensions (e.g. nextgen-gallery). Make data type conversion
case-insensitive.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
The current regex for matching ALTER TABLE CHANGE COLUMN does not match
against a statement where there is nothing after the column data type,
resulting in errors such as:
Error running :
ALTER TABLE wp_ngg_pictures CHANGE COLUMN meta_data meta_data LONGTEXT
---- converted to ----
ALTER TABLE wp_ngg_pictures CHANGE COLUMN meta_data meta_data LONGTEXT
----> ERROR: syntax error at or near "CHANGE"
LINE 1: ALTER TABLE wp_ngg_pictures CHANGE COLUMN meta_data meta_dat...
^
Fix this by making the space before NOT NULL optional.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
[Work In Progress] MySQL performs prefix indexing on a few columns.
PostgreSQL lacks support for prefix indexing (although it does support
expression indexing, which can be used to similar effect), which results
in the following error message:
Error running :
ALTER TABLE wp_comments ADD KEY comment_author_email (comment_author_email(10))
---- converted to ----
CREATE INDEX wp_comments_comment_author_email ON wp_comments (comment_author_email(10)
----> ERROR: syntax error at end of input
LINE 1: ...omment_author_email ON wp_comments (comment_author_email(10)
Since the prefix indexing does not currently appear to be advantageous
(other than working around MySQL row index size limitations), convert
these to full-column indexes.
FIXME: SHOW INDEX needs to be updated so that it returns the requested
prefix length in order to avoid attempted index recreation during schema
upgrades. This could be accomplished by storing the length as a comment
or some other ancillary metadata. This is not implemented yet.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
The order of rows returned from SHOW INDEX is significant, and it is
used to determine the column order in multi-column indexes. Update the
query to return rows in the expected order to avoid errors during
upgrade (e.g. in wp_term_taxonomy_term_id_taxonomy where the column
order is not alphabetical).
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This appears as both "SELECT @@SESSION.sql_mode" checked from wp-db.php
in Wordpress core during startup and as "SHOW VARIABLES LIKE 'sql_mode'"
in several extensions (all-in-one-seo-pack, flash-album-gallery, and
nextgen-gallery on my system). Support both by returning the empty
string, which reports the default MySQL behavior (and avoids attempts to
change the mode, since all current code expects this).
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Wordpress 4 makes use of SHOW COLUMNS and SHOW TABLES in addition to
SHOW INDEX, both with and without the FULL modifier. Implement support
for these statements using queries against INFORMATION_SCHEMA.
Some of these queries use lower-case versions of these statements,
such as "show tables like 'wp_flag_pictures'", so we make sure to
recognize both the upper- and lower-case versions.
This is based, in part, on the work of raptorz in the support forum at
https://wordpress.org/support/topic/upgrade-to-wp421-fail?replies=3#post-6886123
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
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>