1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
from sqlalchemy import MetaData
21
def upgrade(migrate_engine):
23
meta.bind = migrate_engine
25
# NOTE (ironcamel): The only table we are not converting to utf8 here is
26
# dns_domains. This table has a primary key that is 512 characters wide.
27
# When the mysql engine attempts to convert it to utf8, it complains about
28
# not supporting key columns larger than 1000.
30
if migrate_engine.name == "mysql":
32
# tables that are FK parents, must be converted early
33
"aggregates", "console_pools", "instance_types", "instances",
34
"projects", "security_groups", "sm_backend_config", "sm_flavors",
35
"snapshots", "user_project_association", "users", "volume_types",
37
# those that are children and others later
38
"agent_builds", "aggregate_hosts", "aggregate_metadata",
39
"auth_tokens", "block_device_mapping", "bw_usage_cache",
40
"certificates", "compute_nodes", "consoles", "fixed_ips",
41
"floating_ips", "instance_actions", "instance_faults",
42
"instance_info_caches", "instance_metadata",
43
"instance_type_extra_specs", "iscsi_targets", "key_pairs",
44
"migrate_version", "migrations", "networks", "provider_fw_rules",
45
"quotas", "s3_images", "security_group_instance_association",
46
"security_group_rules", "services", "sm_volume",
47
"user_project_role_association", "user_role_association",
48
"virtual_interfaces", "virtual_storage_arrays", "volume_metadata",
49
"volume_type_extra_specs", "zones"]
50
sql = "SET foreign_key_checks = 0;"
52
sql += "ALTER TABLE %s CONVERT TO CHARACTER SET utf8;" % table
53
sql += "SET foreign_key_checks = 1;"
54
sql += "ALTER DATABASE %s DEFAULT CHARACTER SET utf8;" \
55
% migrate_engine.url.database
56
migrate_engine.execute(sql)
59
def downgrade(migrate_engine):
60
# utf8 tables should be backwards compatible, so lets leave it alone