Rename the instance_id column in instance_info_caches.

The name was confusing, because it was a uuid in a column named
instance_id.

Change-Id: I0df0fe84b4891da9529639cf8c07c3e4d86a9958
This commit is contained in:
Michael Still 2012-06-15 17:53:51 +10:00
parent d537f641c7
commit 25c50ca4b3
8 changed files with 247 additions and 6 deletions

View File

@ -1832,7 +1832,7 @@ def instance_info_cache_get(context, instance_uuid, session=None):
session = session or get_session()
info_cache = session.query(models.InstanceInfoCache).\
filter_by(instance_id=instance_uuid).\
filter_by(instance_uuid=instance_uuid).\
first()
return info_cache
@ -1856,7 +1856,7 @@ def instance_info_cache_update(context, instance_uuid, values,
else:
# NOTE(tr3buchet): just in case someone blows away an instance's
# cache entry
values['instance_id'] = instance_uuid
values['instance_uuid'] = instance_uuid
info_cache = instance_info_cache_create(context, values)
return info_cache

View File

@ -0,0 +1,71 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack LLC.
# Copyright 2012 Michael Still and Canonical Inc
# All Rights Reserved.
#
# 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.
from sqlalchemy import select, Column, ForeignKey, Integer
from sqlalchemy import MetaData, String, Table
from migrate import ForeignKeyConstraint
from nova import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instances = Table('instances', meta, autoload=True)
instance_info_caches = Table('instance_info_caches', meta, autoload=True)
# We need to remove the foreign key constraint or the column rename will
# fail
fkeys = list(instance_info_caches.c.instance_id.foreign_keys)
try:
fkey_name = fkeys[0].constraint.name
ForeignKeyConstraint(
columns=[instance_info_caches.c.instance_id],
refcolumns=[instances.c.uuid],
name=fkey_name).drop()
except Exception:
LOG.error(_("foreign key constraint couldn't be removed"))
raise
instance_info_caches.c.instance_id.alter(name='instance_uuid')
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instances = Table('instances', meta, autoload=True)
instance_info_caches = Table('instance_info_caches', meta, autoload=True)
# We need to remove the foreign key constraint or the column rename will
# fail
fkeys = list(instance_info_caches.c.instance_uuid.foreign_keys)
if fkeys:
try:
fkey_name = fkeys[0].constraint.name
ForeignKeyConstraint(
columns=[instance_info_caches.c.instance_uuid],
refcolumns=[instances.c.uuid],
name=fkey_name).drop()
except Exception:
LOG.error(_("foreign key constraint couldn't be removed"))
raise
instance_info_caches.c.instance_uuid.alter(name='instance_id')

View File

@ -0,0 +1,50 @@
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE instance_info_caches_backup (
created_at DATETIME,
updated_at DATETIME,
deleted_at DATETIME,
deleted BOOLEAN,
id INTEGER NOT NULL,
network_info TEXT,
instance_id VARCHAR(36),
PRIMARY KEY (id)
);
INSERT INTO instance_info_caches_backup
SELECT created_at,
updated_at,
deleted_at,
deleted,
id,
network_info,
instance_uuid as instance_id
FROM instance_info_caches;
DROP TABLE instance_info_caches;
CREATE TABLE instance_info_caches (
created_at DATETIME,
updated_at DATETIME,
deleted_at DATETIME,
deleted BOOLEAN,
id INTEGER NOT NULL,
network_info TEXT,
instance_id VARCHAR(36),
PRIMARY KEY (id)
);
CREATE INDEX instance_info_caches_instance_id_idx ON instance_info_caches(instance_id);
INSERT INTO instance_info_caches
SELECT created_at,
updated_at,
deleted_at,
deleted,
id,
network_info,
instance_id
FROM instance_info_caches_backup;
DROP TABLE instance_info_caches_backup;
COMMIT;

View File

@ -0,0 +1,50 @@
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE instance_info_caches_backup (
created_at DATETIME,
updated_at DATETIME,
deleted_at DATETIME,
deleted BOOLEAN,
id INTEGER NOT NULL,
network_info TEXT,
instance_uuid VARCHAR(36),
PRIMARY KEY (id)
);
INSERT INTO instance_info_caches_backup
SELECT created_at,
updated_at,
deleted_at,
deleted,
id,
network_info,
instance_id as instance_uuid
FROM instance_info_caches;
DROP TABLE instance_info_caches;
CREATE TABLE instance_info_caches (
created_at DATETIME,
updated_at DATETIME,
deleted_at DATETIME,
deleted BOOLEAN,
id INTEGER NOT NULL,
network_info TEXT,
instance_uuid VARCHAR(36),
PRIMARY KEY (id)
);
CREATE INDEX instance_info_caches_instance_uuid_idx ON instance_info_caches(instance_uuid);
INSERT INTO instance_info_caches
SELECT created_at,
updated_at,
deleted_at,
deleted,
id,
network_info,
instance_uuid
FROM instance_info_caches_backup;
DROP TABLE instance_info_caches_backup;
COMMIT;

View File

@ -0,0 +1,68 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack LLC.
# Copyright 2012 Michael Still and Canonical Inc
# All Rights Reserved.
#
# 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.
from sqlalchemy import select, Column, ForeignKey, Integer
from sqlalchemy import MetaData, String, Table
from migrate import ForeignKeyConstraint
from nova import log as logging
LOG = logging.getLogger(__name__)
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instances = Table('instances', meta, autoload=True)
for table in ['block_device_mapping',
'consoles',
'instance_info_caches',
'instance_metadata',
'security_group_instance_association']:
t = Table(table, meta, autoload=True)
try:
ForeignKeyConstraint(
columns=[t.c.instance_uuid],
refcolumns=[instances.c.uuid]).create()
except Exception:
LOG.error(_("foreign key constraint couldn't be created"))
raise
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instances = Table('instances', meta, autoload=True)
for table in ['block_device_mapping',
'consoles',
'instance_info_caches',
'instance_metadata',
'security_group_instance_association']:
t = Table(table, meta, autoload=True)
try:
ForeignKeyConstraint(
columns=[t.c.instance_uuid],
refcolumns=[instances.c.uuid]).drop()
except Exception:
LOG.error(_("foreign key constraint couldn't be created"))
raise

View File

@ -0,0 +1 @@
SELECT 'noop';

View File

@ -0,0 +1 @@
SELECT 'noop';

View File

@ -290,12 +290,12 @@ class InstanceInfoCache(BASE, NovaBase):
# text column used for storing a json object of network data for api
network_info = Column(Text)
instance_id = Column(String(36), ForeignKey('instances.uuid'),
nullable=False, unique=True)
instance_uuid = Column(String(36), ForeignKey('instances.uuid'),
nullable=False, unique=True)
instance = relationship(Instance,
backref=backref('info_cache', uselist=False),
foreign_keys=instance_id,
primaryjoin=instance_id == Instance.uuid)
foreign_keys=instance_uuid,
primaryjoin=instance_uuid == Instance.uuid)
class InstanceTypes(BASE, NovaBase):