Happy New Year, Devs!
I hope you’ve had an amazing time with friends and family, and had a chance to recharge your batteries. Now that the holidays are behind us, it’s time to get back in business with some lessons learned and knowledge sharing.
In the 14.2 release, we announced a key update to the default collation for MySQL 8, changing it to utf8mb4_0900_ai_ci
. While MySQL 8.0 and newer already use this collation by default, it’s important to note that it's not included in the mysqldump
output files. That's important If you're migrating to the cloud or upgrading to Sugar 25.1, this discrepancy in collations could cause compatibility issues, impacting your database operations.
While this might not seem immediately necessary for all on-premise customers, consider these points:
- Future-Proofing: If you upgrade to Sugar 25.1, the upgrade process will include this conversion. Running the conversion in advance ensures a smoother, faster upgrade process.
- Controlled Execution: Running the script beforehand allows you to manage and monitor the conversion in a more controlled environment, rather than during the critical upgrade window.
- Performance Impact: Doing the conversion as a separate step allows for better resource allocation and minimizes the performance hit on your system during the upgrade.
Is This Script Required for On-Premise Customers?
While running the script is optional before upgrading, it is mandatory during the upgrade process to Sugar 25.1. Running it in advance will save time and reduce the impact of the upgrade. If performing it during upgrade, the collation conversion could slow down the upgrade substantially, especially for larger databases.
When Should I Convert My On-Premise DB Using This Script?
You should consider running this script before upgrading to Sugar 25.1. This allows the conversion to happen in a controlled, planned manner and avoids delays during the upgrade itself.
The script is designed to be a manual process, giving you the flexibility and control to execute it during a maintenance window or other convenient times for your operations.
Can I Skip This process? Will My Sugar Instance Still Work?
Yes, your Sugar instance will continue to work without running this script. However, the database collation will be converted during the upgrade to Sugar 25.1 automatically.
The script
This script is a separate CLI utility tool that customers who want to prepare their databases for the upgrade and it is not included as part of the Sugar release. A very simple
single-threaded
version of this script is included in the upgrade package and will work for Windows and Linux Sugar installations with MySQL.The multi-process version is only applicable for Linux but will still work on Windows too, but in a single-threded way.
Key Features:
- The goal is to ensure that customers have the clarity and tools to make an informed decision about when and how to apply this script to their environments.
- Supports dry-run testing to validate changes.
- Multi-threaded processing for faster conversions.
- Logs the process, including potential failures and table sizes before/after conversion.
Prerequisites
- PHP 8.0 or higher.
- MySQL 8.0+.
Permissions
- Full database access to execute ALTER TABLE operations.
- CLI access to run the script.
Recommendations
- Run during maintenance windows.
- Back up the database before starting the conversion.
How to Use the Script
- Copy this script and place it on your SugarCRM root directory as collUpdateAlter.php
-
12345678910111213141516171819202122232425262728<?php/** Your installation or use of this SugarCRM file is subject to the applicable* terms available at* http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.* If you do not agree to all of the applicable terms or do not have the* authority to bind the entity as an authorized representative, then do not* install or use this SugarCRM file.** Copyright (C) SugarCRM Inc. All rights reserved.*/if (!str_contains(php_sapi_name(), 'cli')) {die('This is CLI only.');}require 'vendor/autoload.php';// Initialize global objects$timedate = TimeDate::getInstance();$GLOBALS['timedate'] = $timedate;$cfg = new Configurator();$db = DBManagerFactory::getInstance();$platform = $db->getConnection()->getDatabasePlatform();// Configurationconst LOG_FILE = 'table_sizes_log.txt';const DRY_RUN_PREFIX = 'dry_run_before_alter_';
- Run the Script
- php collUpdateAlter.php --max-threads=<number> --skip-tables=<table_names>
--max-threads
: Limits the number of threads used.--skip-tables
: Excludes specified tables from conversion.
- php collUpdateAlter.php --max-threads=<number> --skip-tables=<table_names>
- Monitor Logs
- The script writes logs to
table_sizes_log.txt
.
- The script writes logs to
- Verify Changes
- Check the final log entries for completion.
- Ensure database collation matches the target:
utf8mb4_0900_ai_ci
.
Handling Issues and Errors
- Interrupted Process: Manually resume using the same parameters.
- Out Of Memory Errors: Ensure the system has enough memory or run the script table-by-table for large databases.
- Inconsistent Collation: Validate that all table collations match after completing the script.
Happy conversion folks!