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
This commit is contained in:
Jimmy McCrory 2016-06-23 21:43:22 -07:00 committed by Jesse Pretorius (odyssey4me)
parent 739bff576f
commit 63012f0c40
3 changed files with 68 additions and 0 deletions

View File

@ -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
~~~~~~~~~~~~~

View File

@ -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")

View File

@ -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+$")