From 63012f0c40538a11c5031b7f2e9927fcfd40dd88 Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Thu, 23 Jun 2016 21:43:22 -0700 Subject: [PATCH] Add upgrade playbook to update database collations Since the default database collation has changed, include an upgrade playbook to ensure that existing tables and databases with the previous collation are converted during upgrades from Mitaka. Change-Id: Iadbcf50c9611561b56fa1ea6ef3e80f636e0c0a8 Depends-on: I8507b6c9bd058bb308cc089f3802e52e24bea324 --- doc/source/upgrade-guide/manual-upgrade.rst | 10 ++++ scripts/run-upgrade.sh | 1 + .../playbooks/db-collation-alter.yml | 57 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 scripts/upgrade-utilities/playbooks/db-collation-alter.yml 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+$")