prefix . 'wc_product_meta_lookup', 'sku'); if (!$target) { Log::write("Migration 1.2.4: wc_product_meta_lookup.sku not found, nothing to align", Log::WARNING, Log::CONTEXT_GENERAL); return; } $columns = [ $wpdb->prefix . 'actionwear_products' => ['sku', 'VARCHAR(64)', 'NOT NULL'], $wpdb->prefix . 'actionwear_images' => ['sku', 'VARCHAR(255)', 'NOT NULL'], ]; foreach ($columns as $table => $definition) { list($column, $type, $nullability) = $definition; $current = SqlManager::getColumnCollation($table, $column); if (!$current || $current['collation'] === $target['collation']) { continue; } // CHARACTER SET / COLLATE must come before NOT NULL in a column definition $sql = "ALTER TABLE `{$table}` MODIFY `{$column}` {$type} CHARACTER SET {$target['charset']} COLLATE {$target['collation']} {$nullability}"; $wpdb->query($sql); if ($wpdb->last_error) { // Duplicate keys under the new collation, missing privileges, locked table... // The runtime fallback in SqlManager::skuJoinExpr() keeps the joins working. Log::write("Migration 1.2.4: could not align {$table}.{$column} to {$target['collation']} - " . $wpdb->last_error, Log::ERROR, Log::CONTEXT_GENERAL); continue; } Log::write("Migration 1.2.4: {$table}.{$column} aligned from {$current['collation']} to {$target['collation']}", Log::INFO, Log::CONTEXT_GENERAL); } SqlManager::resetCollationCache(); } } }