Skip to content

Migrate public to private metakey#108

Open
tijmenbruggeman wants to merge 21 commits into
tinify:masterfrom
wcreateweb:migrate-public-to-private-metakey
Open

Migrate public to private metakey#108
tijmenbruggeman wants to merge 21 commits into
tinify:masterfrom
wcreateweb:migrate-public-to-private-metakey

Conversation

@tijmenbruggeman
Copy link
Copy Markdown
Collaborator

@tijmenbruggeman tijmenbruggeman commented May 15, 2026

Will migrate the tiny_compress_images to _tiny_compress_images marking it as a private key. This will ensure that the field will not be editable through custom fields.

Changed

  • Added Tiny_Migrate class to contain migrations.
    • It has a method run which runs before the plugin does (see tiny-compress-images.php)
    • The method will compare a const DB_VERSION_NR to the stored version
      • If the stored version number is higher than the constant, it will exit and not run migrations.
      • If the stored version does not exist or is lower it will run down the path to check migrations
    • For standards, each migration:
      • will have a associated version number.
      • is a private static in the migration class

Considerations

  • Why a seperate version number for the database and not follow plugin versions? It will be easier to follow on which version you are on. 1 -> 2 -> 3 is easier to follow than 3.7.0 -> 4.2.0 -> 5.6.0.
  • When comparing to Utm tracking to links, add meta key prefix #34, what are the differences? The other version uses a N+1 loop to do a separate db query which might end up with a ton of queries. PR 34 also does a update and then delete which is two queries. Straight update (https://developer.wordpress.org/reference/classes/wpdb/update/) is considerably more stable and reliable.

After merging, we can close:

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the plugin's post meta key private by renaming tiny_compress_images_tiny_compress_images (so it no longer appears in WordPress's Custom Fields UI), and introduces a lightweight, version-tracked migration framework that rewrites existing meta rows in a single $wpdb->update call. A Tiny_Migrate::run() invocation is added to the main plugin bootstrap so the rename is applied automatically on upgrade.

Changes:

  • Change Tiny_Config::META_KEY to _tiny_compress_images and update the meta-key invariant test hash.
  • Add Tiny_Migrate class with a DB_VERSION / tinypng_db_version option to gate one-shot migrations, plus a first migration that renames the existing meta keys.
  • Extend the WordPress test stubs to support $wpdb->update, non-callable stub values, and a postmeta table name; add unit tests for Tiny_Migrate.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tiny-compress-images.php Loads new migration class and runs migrations at plugin bootstrap.
src/class-tiny-migrate.php New migration runner with DB_VERSION tracking and the meta-key rename migration.
src/config/class-tiny-config.php Prefixes META_KEY with an underscore to make it private.
readme.txt Adds a = 3.7.0 = changelog entry for the meta-key migration.
test/helpers/wordpress.php Exposes postmeta, registers an update method, and permits non-callable stub return values.
test/unit/TinyMigrateTest.php New unit tests for the migration's run / skip / option-update behaviours.
test/unit/TinyImageTest.php Updates the SHA-1 invariant test for the new meta-key value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tiny-compress-images.php Outdated
Comment thread src/class-tiny-migrate.php
Comment thread src/class-tiny-migrate.php
Comment thread src/class-tiny-migrate.php
Comment thread readme.txt
Comment thread src/class-tiny-migrate.php Outdated
Comment thread test/helpers/wordpress.php Outdated
Comment thread test/unit/TinyMigrateTest.php
Comment thread src/class-tiny-migrate.php Outdated
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