Add user_id column to the instance_mappings table
The instance_mappings table already contains the project_id for an instance. This adds the corresponding user_id. This also adds an index on (user_id, project_id) because later patches in this series will be using these columns for quota counting. Part of blueprint count-quota-usage-from-placement Change-Id: Id9eef7a58f66c73cd638c6c3e228447b7ab81e34
This commit is contained in:
parent
131f7606c1
commit
9073445b38
@ -0,0 +1,32 @@
|
||||
# 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 Column
|
||||
from sqlalchemy import Index
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
instance_mappings = Table('instance_mappings', meta, autoload=True)
|
||||
|
||||
if not hasattr(instance_mappings.c, 'user_id'):
|
||||
instance_mappings.create_column(Column('user_id', String(length=255),
|
||||
nullable=True))
|
||||
index = Index('instance_mappings_user_id_project_id_idx',
|
||||
instance_mappings.c.user_id,
|
||||
instance_mappings.c.project_id)
|
||||
index.create()
|
@ -134,13 +134,18 @@ class InstanceMapping(API_BASE):
|
||||
__table_args__ = (Index('project_id_idx', 'project_id'),
|
||||
Index('instance_uuid_idx', 'instance_uuid'),
|
||||
schema.UniqueConstraint('instance_uuid',
|
||||
name='uniq_instance_mappings0instance_uuid'))
|
||||
name='uniq_instance_mappings0instance_uuid'),
|
||||
Index('instance_mappings_user_id_project_id_idx',
|
||||
'user_id', 'project_id'))
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
instance_uuid = Column(String(36), nullable=False)
|
||||
cell_id = Column(Integer, ForeignKey('cell_mappings.id'),
|
||||
nullable=True)
|
||||
project_id = Column(String(255), nullable=False)
|
||||
# FIXME(melwitt): This should eventually be non-nullable, but we need a
|
||||
# transition period first.
|
||||
user_id = Column(String(255), nullable=True)
|
||||
queued_for_delete = Column(Boolean)
|
||||
cell_mapping = orm.relationship('CellMapping',
|
||||
backref=backref('instance_mapping', uselist=False),
|
||||
|
@ -726,6 +726,11 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
|
||||
self.assertColumnExists(engine, 'instance_mappings',
|
||||
'queued_for_delete')
|
||||
|
||||
def _check_062(self, engine, data):
|
||||
self.assertColumnExists(engine, 'instance_mappings', 'user_id')
|
||||
self.assertIndexExists(engine, 'instance_mappings',
|
||||
'instance_mappings_user_id_project_id_idx')
|
||||
|
||||
|
||||
class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk,
|
||||
test_fixtures.OpportunisticDBTestMixin,
|
||||
|
Loading…
Reference in New Issue
Block a user