v1.3.0
This commit is contained in:
parent
650e69349f
commit
672d0f295f
11 changed files with 438 additions and 73 deletions
|
|
@ -23,6 +23,7 @@ class Database {
|
|||
public static function create_tables(): void {
|
||||
self::migration_100();
|
||||
self::migration_101();
|
||||
self::migration_110();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -43,6 +44,10 @@ class Database {
|
|||
if ( version_compare( $current, '1.0.1', '<' ) ) {
|
||||
self::migration_101();
|
||||
}
|
||||
|
||||
if ( version_compare( $current, '1.1.0', '<' ) ) {
|
||||
self::migration_110();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,6 +57,7 @@ class Database {
|
|||
*/
|
||||
public static function drop_tables(): void {
|
||||
global $wpdb;
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}mra_provider_status`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}mra_external_results`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}mra_media_usage`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}mra_media_index`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
|
|
@ -68,6 +74,7 @@ class Database {
|
|||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->query( "TRUNCATE TABLE `{$wpdb->prefix}mra_provider_status`" );
|
||||
$wpdb->query( "TRUNCATE TABLE `{$wpdb->prefix}mra_external_results`" );
|
||||
$wpdb->query( "TRUNCATE TABLE `{$wpdb->prefix}mra_media_usage`" );
|
||||
$wpdb->query( "TRUNCATE TABLE `{$wpdb->prefix}mra_media_index`" );
|
||||
|
|
@ -125,7 +132,7 @@ class Database {
|
|||
"CREATE TABLE {$wpdb->prefix}mra_external_results (
|
||||
result_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
attachment_id bigint(20) unsigned NOT NULL,
|
||||
provider enum('google_vision','tineye') NOT NULL,
|
||||
provider varchar(100) NOT NULL,
|
||||
raw_response json DEFAULT NULL,
|
||||
match_count int(10) unsigned NOT NULL DEFAULT 0,
|
||||
top_domains json DEFAULT NULL,
|
||||
|
|
@ -155,4 +162,57 @@ class Database {
|
|||
);
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.SchemaChange
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration 1.1.0 — widens provider column and adds mra_provider_status table.
|
||||
*
|
||||
* Changes:
|
||||
* - ALTER mra_external_results.provider from ENUM to varchar(100) for extensibility.
|
||||
* - CREATE mra_provider_status for per-provider scan tracking.
|
||||
* - Backfill mra_provider_status from existing mra_external_results data.
|
||||
*
|
||||
* Safe to re-run: ALTER TABLE is a no-op if already varchar(100);
|
||||
* dbDelta skips existing tables; INSERT IGNORE skips duplicate rows.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function migration_110(): void {
|
||||
global $wpdb;
|
||||
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.SchemaChange
|
||||
$wpdb->query(
|
||||
"ALTER TABLE `{$wpdb->prefix}mra_external_results`
|
||||
MODIFY COLUMN provider varchar(100) NOT NULL"
|
||||
);
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.SchemaChange
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
|
||||
dbDelta(
|
||||
"CREATE TABLE {$wpdb->prefix}mra_provider_status (
|
||||
attachment_id bigint(20) unsigned NOT NULL,
|
||||
provider varchar(100) NOT NULL,
|
||||
status enum('pending','queued','scanned','error') NOT NULL DEFAULT 'pending',
|
||||
scanned_at datetime DEFAULT NULL,
|
||||
PRIMARY KEY (attachment_id,provider),
|
||||
KEY status (status)
|
||||
) {$charset_collate};"
|
||||
);
|
||||
|
||||
// Backfill from existing data. Idempotent: INSERT IGNORE skips duplicates.
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->query(
|
||||
"INSERT IGNORE INTO {$wpdb->prefix}mra_provider_status (attachment_id, provider, status, scanned_at)
|
||||
SELECT er.attachment_id, er.provider,
|
||||
CASE WHEN mi.external_status = 'error' THEN 'error'
|
||||
WHEN mi.external_status = 'queued' THEN 'queued'
|
||||
ELSE 'scanned' END,
|
||||
mi.external_scanned_at
|
||||
FROM {$wpdb->prefix}mra_external_results er
|
||||
JOIN {$wpdb->prefix}mra_media_index mi ON mi.attachment_id = er.attachment_id"
|
||||
);
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue