CI: More testing with custom mysql.cnf file

This commit is contained in:
Griatch 2025-12-19 14:37:41 +01:00
parent 2a24842734
commit 2e5e1de9ce
3 changed files with 34 additions and 12 deletions

View file

@ -46,24 +46,39 @@ runs:
- name: Set up MySQL Configuration and Privileges
if: ${{ inputs.database == 'mysql' }}
run: |
# Set MySQL global variables for character set, collation, and row format
# These must be set before migrations run to ensure tables are created with correct settings
# Create MySQL config file inside the container and restart MySQL to apply settings
# This ensures settings are applied at server startup, similar to command-line arguments
CONTAINER_ID=$(docker ps --filter "ancestor=mysql:8.0" --format "{{.ID}}" | head -1)
if [ -n "$CONTAINER_ID" ]; then
# Create config file in container
docker exec $CONTAINER_ID sh -c 'printf "[mysqld]\ncharacter-set-server=utf8mb4\ncollation-server=utf8mb4_unicode_ci\ninnodb-default-row-format=DYNAMIC\n" > /etc/mysql/conf.d/custom.cnf'
# Restart MySQL to apply config (graceful shutdown and start)
docker exec $CONTAINER_ID sh -c 'mysqladmin -u root -proot_password shutdown' || true
sleep 2
docker start $CONTAINER_ID
# Wait for MySQL to be ready again
until mysqladmin ping -h 127.0.0.1 -u root -proot_password --silent; do
sleep 1
echo -n .
done
fi
# Also set global variables as a fallback (though config file should handle this)
mysql -u root -proot_password -h 127.0.0.1 mysql <<EOF
SET GLOBAL character_set_server = 'utf8mb4';
SET GLOBAL collation_server = 'utf8mb4_unicode_ci';
SET GLOBAL innodb_default_row_format = 'DYNAMIC';
SET GLOBAL character_set_server = 'utf8mb4';
SET GLOBAL collation_server = 'utf8mb4_unicode_ci';
SET GLOBAL innodb_default_row_format = 'DYNAMIC';
EOF
# Ensure user exists and has proper privileges
mysql -u root -proot_password -h 127.0.0.1 mysql <<EOF
CREATE USER IF NOT EXISTS 'evennia'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON \`evennia%\`.* TO 'evennia'@'%';
GRANT PROCESS ON *.* TO 'evennia'@'%';
GRANT SESSION_VARIABLES_ADMIN ON *.* TO 'evennia'@'%';
FLUSH PRIVILEGES;
CREATE USER IF NOT EXISTS 'evennia'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON \`evennia%\`.* TO 'evennia'@'%';
GRANT PROCESS ON *.* TO 'evennia'@'%';
GRANT SESSION_VARIABLES_ADMIN ON *.* TO 'evennia'@'%';
FLUSH PRIVILEGES;
EOF
# Set database character set and collation
mysql -u root -proot_password -h 127.0.0.1 evennia <<EOF
ALTER DATABASE evennia CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER DATABASE evennia CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EOF
shell: bash

5
.github/workflows/mysql.cnf vendored Normal file
View file

@ -0,0 +1,5 @@
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
innodb-default-row-format=DYNAMIC

View file

@ -48,7 +48,9 @@ DATABASES = {
"PORT": "", # use default port
"OPTIONS": {
"charset": "utf8mb4",
# Note: MySQL server is configured with utf8mb4 and DYNAMIC row format at startup
# Note: MySQL server global settings (character set, collation, row format) are set
# in setup-database action before migrations run. The init_command sets per-connection
# variables that don't require special privileges.
"init_command": (
"SET collation_connection=utf8mb4_unicode_ci, "
"sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1"