Skip to content

Support multi-value column type modifiers for _mysql_data_types_cache#126

Merged
bgrgicak merged 4 commits intoWordPress:mainfrom
jeroenpf:fix/support-decimal-columns-in-show-create
Jul 18, 2024
Merged

Support multi-value column type modifiers for _mysql_data_types_cache#126
bgrgicak merged 4 commits intoWordPress:mainfrom
jeroenpf:fix/support-decimal-columns-in-show-create

Conversation

@jeroenpf
Copy link
Copy Markdown
Contributor

@jeroenpf jeroenpf commented Jul 17, 2024

Fixes: #122

This fix will skip over tokens until it finds the closing bracket of the type modifier ) instead of consuming exactly 3. This should account for data types that support more than one value as a modifier, such as: enum, float, decimal, double.

Additionally, I've added support for enums. There are plugins that use enum fields and it makes sense to convert those to text in SQLite.

Testing instructions

Confirm the tests pass

@katinthehatsite
Copy link
Copy Markdown

Thanks for adding the test - are there any other steps that I could manually run on my end to confirm that the issue is fixed?

@jeroenpf
Copy link
Copy Markdown
Contributor Author

@katinthehatsite

The unit tests should cover this change but if you want to do it manually you could try:

Create a site in Studio, replace the sqlite database integration plugin with a clone of this repo and branch and then install a plugin that uses enum and/or decimal fields. The woocommerce plugin will add tables with decimals and the redirection plugin will create tables with enums.

After you installed those plugins, you can inspect the _mysql_data_types_cache table and ensure that the columns that have decimal or enum types are properly represented in that table.

After that you can try and run a query using $wpdb->query('SHOW CREATE table);` and see if it outputs a valid MySQL-compatible create statement.

@bgrgicak
Copy link
Copy Markdown
Collaborator

Thanks @jeroenpf! The PR looks good.

@bgrgicak bgrgicak merged commit d24fff8 into WordPress:main Jul 18, 2024
JanJakes added a commit that referenced this pull request Jan 29, 2026
…migrator (#312)

When migrating from the legacy SQLite driver to the new AST-based
driver, the information schema reconstructor reads MySQL column type
metadata from the `_mysql_data_types_cache` table. Some older versions
of the legacy driver stored invalid type definitions in this table,
causing migration failures.

This PR detects and handles two types of invalid data:

**1. Truncated decimal definitions** — Before [PR
#126](#126),
columns with multiple type arguments like `decimal(26, 8)` were
incorrectly stored as `decimal(26,` (missing the second argument and
closing parenthesis). For WooCommerce tables, the fix restores the
correct decimal precision based on known WooCommerce column patterns.
For other tables, these invalid definitions are discarded and the column
type is inferred from SQLite.

**2. Index definitions mistaken for columns** — Before [commit
b5a9fba](b5a9fba),
index definitions like `KEY timestamp (timestamp)` were incorrectly
parsed and stored as column `KEY` with type `timestamp(timestamp)`. The
fix validates that type arguments are numeric, rejecting these malformed
entries and falling back to the SQLite type inference.

Fixes WordPress/wordpress-playground#3050.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Decimal column type not stored correctly in _mysql_data_types_cache

3 participants