~ubuntu-branches/ubuntu/trusty/cinder/trusty

« back to all changes in this revision

Viewing changes to cinder/db/sqlalchemy/migrate_repo/versions/077_convert_to_utf8.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-22 09:57:46 UTC
  • Revision ID: package-import@ubuntu.com-20120522095746-9lm71yvzltjybk4b
Tags: upstream-2012.2~f1~20120503.2
ImportĀ upstreamĀ versionĀ 2012.2~f1~20120503.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
from sqlalchemy import MetaData
 
19
 
 
20
 
 
21
def upgrade(migrate_engine):
 
22
    meta = MetaData()
 
23
    meta.bind = migrate_engine
 
24
 
 
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.
 
29
 
 
30
    if migrate_engine.name == "mysql":
 
31
        tables = [
 
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",
 
36
            "volumes",
 
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;"
 
51
        for table in tables:
 
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)
 
57
 
 
58
 
 
59
def downgrade(migrate_engine):
 
60
    # utf8 tables should be backwards compatible, so lets leave it alone
 
61
    pass