fix: harden account_filter migration with explicit ALTER (closes #47)#48
Merged
Conversation
closes #47) Relying on dbDelta() to add account_filter to an existing outpost_hashtags table is fragile (dbDelta is formatting-sensitive). Add a deterministic, idempotent column check + ALTER TABLE in create_tables() (ensure_columns()), so both activation and maybe_upgrade() reliably add the column on in-place upgrades. Verified in a real WordPress install on the SQLite drop-in: upgrading a pre-1.1.0-schema table now adds the column and is idempotent. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Hardens the plugin’s schema migration for the outpost_hashtags.account_filter column by avoiding reliance on dbDelta()’s formatting-sensitive diffing behavior, ensuring deterministic upgrades (notably for SQLite drop-in environments).
Changes:
- Calls a new
ensure_columns()fromcreate_tables()to explicitly add later-introduced columns via idempotentALTER TABLE ... ADD COLUMN. - Adds
column_exists()helper used to detect whetheraccount_filteris present before applying the migration. - Updates the
maybe_upgrade()comment to reflect the new deterministic migration step.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
| private static function column_exists( $table, $column ) { | ||
| global $wpdb; | ||
| // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- trusted table name; column is placeheld. |
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.
Found during Phase A behavioral verification. Closes #47.
What
The 1.1.0 upgrade added
account_filterby re-runningdbDelta()over theCREATE TABLE. dbDelta's in-place column diffing is formatting-sensitive and unreliable; in a real WordPress + SQLite test it did not add the column on an upgrade. Added an explicit, idempotentensure_columns()(column check +ALTER TABLE ... ADD COLUMN) called fromcreate_tables(), so activation andmaybe_upgrade()both add it deterministically.Verified (real WordPress, SQLite drop-in)
maybe_upgrade()→ column added, db_version → 1.2.0, insert withaccount_filtersucceeds.CREATE TABLE).PHPCS exit 0, 22/22 unit tests pass.
Closes #47
🤖 Generated with Claude Code