diff --git a/doc/source/upgrade-guide/manual-upgrade.rst b/doc/source/upgrade-guide/manual-upgrade.rst index 3634901b6b..6e172fe803 100644 --- a/doc/source/upgrade-guide/manual-upgrade.rst +++ b/doc/source/upgrade-guide/manual-upgrade.rst @@ -119,6 +119,16 @@ See :ref:`user-secrets-playbook` for more details. # openstack-ansible "${UPGRADE_PLAYBOOKS}/user-secrets-adjustment.yml" +Update database collations +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The default database collation has been changed to `utf8_general_ci`. This play +performs a conversion on existing databases and tables. + +.. code-block:: console + + # openstack-ansible "${UPGRADE_PLAYBOOKS}/db-collation-alter.yml + Upgrade hosts ~~~~~~~~~~~~~ diff --git a/scripts/run-upgrade.sh b/scripts/run-upgrade.sh index 496e5b4460..acc602ca27 100755 --- a/scripts/run-upgrade.sh +++ b/scripts/run-upgrade.sh @@ -144,6 +144,7 @@ function main { RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/ansible_fact_cleanup.yml") RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/deploy-config-changes.yml") RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/user-secrets-adjustment.yml") + RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/db-collation-alter.yml") RUN_TASKS+=("setup-hosts.yml --limit '!galera_all[0]'") RUN_TASKS+=("lxc-containers-create.yml --limit galera_all[0]") RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/repo-server-pip-conf-removal.yml") diff --git a/scripts/upgrade-utilities/playbooks/db-collation-alter.yml b/scripts/upgrade-utilities/playbooks/db-collation-alter.yml new file mode 100644 index 0000000000..ee16e7965a --- /dev/null +++ b/scripts/upgrade-utilities/playbooks/db-collation-alter.yml @@ -0,0 +1,57 @@ +--- +# Copyright 2016, @WalmartLabs +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Update database collations + hosts: galera_all[0] + gather_facts: false + user: root + tasks: + - name: Find tables with utf8_unicode_ci collation + command: > + mysql -e + "SELECT T.table_schema, T.table_name FROM information_schema.`TABLES` T, + information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA + WHERE CCSA.collation_name = T.table_collation AND CCSA.CHARACTER_SET_NAME = 'utf8' + AND CCSA.COLLATION_NAME = 'utf8_unicode_ci';" + register: utf8_unicode_ci_tables + - name: Disable foreign key checks + command: > + mysql -e + "SET foreign_key_checks = 0;" + when: utf8_unicode_ci_tables.stdout_lines | length > 0 + - name: Convert tables to utf8_general_ci collation + command: > + mysql -e + "ALTER TABLE {{ item.split()[1] }} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;" + {{ item.split()[0] }} + with_items: "{{ utf8_unicode_ci_tables.stdout_lines }}" + when: item | search("^(?!table_schema)\w+\t\w+$") + - name: Enable foreign key checks + command: > + mysql -e + "SET foreign_key_checks = 1;" + when: utf8_unicode_ci_tables.stdout_lines | length > 0 + - name: Find databases with utf8_unicode_ci collation + command: > + mysql -e + "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA + WHERE DEFAULT_CHARACTER_SET_NAME = 'utf8' AND DEFAULT_COLLATION_NAME = 'utf8_unicode_ci';" + register: utf8_unicode_ci_databases + - name: Convert databases to utf8_general_ci collation + command: > + mysql -e + "ALTER DATABASE {{ item }} CHARACTER SET utf8 COLLATE utf8_general_ci;" + with_items: "{{ utf8_unicode_ci_databases.stdout_lines }}" + when: item | search("^(?!SCHEMA_NAME)\w+$")