Conversation
… in dbDelta The chat_sessions table was the only Data Machine table using column COMMENT clauses in its CREATE TABLE SQL. WordPress dbDelta() parses SQL with regex and silently fails on COMMENT strings (especially ones with parentheses). On SQLite via Studio, this caused the table to never be created, while the db_version was still bumped — so the migration never retried. The scheduled cleanup action then spammed the error log with 'no such table: wp_datamachine_chat_sessions' on every Action Scheduler run. - Remove all COMMENT clauses from CREATE TABLE (matches every other Data Machine table; column docs belong in code, not schema) - Fix mixed tab/space indentation in the SQL string - Add table_exists() guard to the cleanup action as defense-in-depth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
COMMENTclauses from thechat_sessionsCREATE TABLE SQL —dbDelta()silently fails to parse them (especially strings with parentheses), preventing the table from ever being created on SQLitetable_exists()guard to thedatamachine_cleanup_chat_sessionsAction Scheduler callback as defense-in-depthRoot Cause
chat_sessionswas the only Data Machine table withCOMMENTclauses in its column definitions. WordPressdbDelta()parses SQL with regex and is notoriously fragile with non-standard extensions. The COMMENT strings (e.g.COMMENT 'First-class agent identity (nullable for backward compatibility)') causeddbDelta()to silently fail on SQLite via Studio.The version was still bumped at the end of
datamachine_activate_for_site(), so the migration never retried. Meanwhile, the scheduled cleanup action fired repeatedly →DELETE FROM wp_datamachine_chat_sessions→no such table→ 70+ identical error log entries.After This Fix
On the next deploy/version bump,
datamachine_maybe_run_migrations()will re-runChat::create_table()with the clean SQL and the table will be created. The cleanup guard prevents log spam if table creation fails for any other reason in the future.