Skip to content

Fix SQLite migration - #387

Merged
aristath merged 4 commits into
developfrom
filip/test-sqlite
Mar 27, 2025
Merged

Fix SQLite migration#387
aristath merged 4 commits into
developfrom
filip/test-sqlite

Conversation

@ilicfilip

@ilicfilip ilicfilip commented Mar 27, 2025

Copy link
Copy Markdown
Collaborator

Yesterday we have added a fix for SQLite error we had reported, but it turns out it broke the Playground instance (which uses SQLite) with the following

error

<div style="clear:both;margin-bottom:2px;border:red dotted thin;" class="error_message" style="border-bottom:dotted blue thin;">
Error occurred at line 4164 in Function <code>handle_error</code>. Error message was: SQLSTATE[HY000]: General error: 1 no such column: data_id.
</div>
<p>Backtrace:</p>
<pre>#0 /internal/shared/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(287): WP_SQLite_Translator->get_error_message()
#1 /wordpress/wp-includes/class-wpdb.php(3): WP_SQLite_DB->query('SELECT * FROM `...')
#2 /wordpress/wp-content/plugins/progress-planner-develop/classes/class-query.php(161): wpdb->get_results('SELECT * FROM `...')
#3 /wordpress/wp-content/plugins/progress-planner-develop/classes/actions/class-content.php(224): Progress_Planner\Query->query_activities(Array, 'RAW')
#4 /wordpress/wp-content/plugins/progress-planner-develop/classes/actions/class-content.php(97): Progress_Planner\Actions\Content->is_there_recent_activity(Object(WP_Post), 'publish')
#5 /wordpress/wp-includes/class-wp-hook.php(3): Progress_Planner\Actions\Content->transition_post_status('publish', 'new', Object(WP_Post))
#6 /wordpress/wp-includes/class-wp-hook.php(3): WP_Hook->apply_filters(NULL, Array)
#7 /wordpress/wp-includes/plugin.php(2): WP_Hook->do_action(Array)
#8 /wordpress/wp-includes/post.php(2): do_action('transition_post...', 'publish', 'new', Object(WP_Post))
#9 /wordpress/wp-includes/post.php(2): wp_transition_post_status('publish', 'new', Object(WP_Post))
#10 /wordpress/wp-content/plugins/progress-planner-develop/classes/class-playground.php(193): wp_insert_post(Array)
#11 /wordpress/wp-content/plugins/progress-planner-develop/classes/class-playground.php(164): Progress_Planner\Playground->create_random_post()
#12 /wordpress/wp-content/plugins/progress-planner-develop/classes/class-playground.php(31): Progress_Planner\Playground->generate_data()
#13 /wordpress/wp-includes/class-wp-hook.php(3): Progress_Planner\Playground->register_hooks('')
#14 /wordpress/wp-includes/class-wp-hook.php(3): WP_Hook->apply_filters(NULL, Array)
#15 /wordpress/wp-includes/plugin.php(2): WP_Hook->do_action(Array)
#16 /wordpress/wp-settings.php(2): do_action('init')
#17 /wordpress/wp-config.php(102): require_once('/wordpress/wp-s...')
#18 /wordpress/wp-load.php(2): require_once('/wordpress/wp-c...')
#19 /wordpress/wp-admin/admin.php(2): require_once('/wordpress/wp-l...')
#20 {main}</pre>
 for query SELECT * FROM `wp_progress_planner_activities` WHERE category = 'content' AND type = 'publish' AND data_id = '4' made by require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, Progress_Planner\Playground->register_hooks, Progress_Planner\Playground->generate_data, Progress_Planner\Playground->create_random_post, wp_insert_post, wp_transition_post_status, do_action('transition_post_status'), WP_Hook->do_action, WP_Hook->apply_filters, Progress_Planner\Actions\Content->transition_post_status, Progress_Planner\Actions\Content->is_there_recent_activity, Progress_Planner\Query->query_activities, WP_SQLite_DB->query, WP_SQLite_DB->print_error
[27-Mar-2025 12:21:46 UTC] WordPress database error <div style="clear:both">&nbsp;</div>
<div class="queries" style="clear:both;margin-bottom:2px;border:red dotted thin;">
<p>MySQL query:</p>
<p>INSERT INTO `wp_progress_planner_activities` (`date`, `category`, `type`, `data_id`, `user_id`) VALUES ('2024-05-02 04:13:02', 'content', 'publish', '4', 1)</p>
<p>Queries made or created this session were:</p>
<ol>
<li>Executing: BEGIN | (no parameters)</li>
<li>Executing: INSERT INTO `wp_progress_planner_activities` (`date`, `category`, `type`, `data_id`, `user_id`) VALUES (:param0 , :param1 , :param2 , :param3 , 1) | parameters: 2024-05-02 04:13:0

Basically the problems were caused by data_id missing, which means our migration script must have deleted it.

But why? It should run only if data_id is INT, which is not for several months now.

The reason is that $wpdb->get_row( "DESCRIBE $table_name data_id" )->Type ) actually doesn't work in SQLite.
SQLite doesn't have DESCRIBE command and SQLite plugin tries to transliterate it, but the end result is not the result for the specific column we wanted (data_id), it is for all columns in the table - and first row in the table is id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT. So migration was running because wrong column was checked.

This solution should work for both DB Engines, I have tested them in both but since I had problems with setting up SQlite plugin locally it would be good if someone double checks it.

@github-actions

github-actions Bot commented Mar 27, 2025

Copy link
Copy Markdown
Contributor

Test merged PR on Playground
Test this pull request on the Playground or download the zip.

@ilicfilip ilicfilip changed the title Remove SQLite migration to test Fix SQLite migration Mar 27, 2025
@ilicfilip
ilicfilip requested a review from aristath March 27, 2025 14:28
@aristath
aristath merged commit 05e0b72 into develop Mar 27, 2025
@ilicfilip
ilicfilip deleted the filip/test-sqlite branch March 27, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants