Add instance/instance_uuid to build_requests table
New fields keep needing to be added to build_requests in order to capture all of the relevant instance information necessary. At this point it's simpler to just embed a serialized Instance object in the db. A column for that is added, as well as an instance_uuid column for indexed lookups. Change-Id: I1628ddd8cb75b4d0a7bbcd2720536c2e0bfc6043 Partially-implements: bp add-buildrequest-obj
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
# 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 migrate import UniqueConstraint
|
||||||
|
from sqlalchemy import Column
|
||||||
|
from sqlalchemy.engine import reflection
|
||||||
|
from sqlalchemy import Index
|
||||||
|
from sqlalchemy import MetaData
|
||||||
|
from sqlalchemy import String
|
||||||
|
from sqlalchemy import Table
|
||||||
|
from sqlalchemy import Text
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(migrate_engine):
|
||||||
|
meta = MetaData()
|
||||||
|
meta.bind = migrate_engine
|
||||||
|
|
||||||
|
build_requests = Table('build_requests', meta, autoload=True)
|
||||||
|
|
||||||
|
columns_to_add = [
|
||||||
|
('instance_uuid',
|
||||||
|
Column('instance_uuid', String(length=36))),
|
||||||
|
('instance',
|
||||||
|
Column('instance', Text())),
|
||||||
|
]
|
||||||
|
for (col_name, column) in columns_to_add:
|
||||||
|
if not hasattr(build_requests.c, col_name):
|
||||||
|
build_requests.create_column(column)
|
||||||
|
|
||||||
|
for index in build_requests.indexes:
|
||||||
|
if [c.name for c in index.columns] == ['instance_uuid']:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
index = Index('build_requests_instance_uuid_idx',
|
||||||
|
build_requests.c.instance_uuid)
|
||||||
|
index.create()
|
||||||
|
|
||||||
|
inspector = reflection.Inspector.from_engine(migrate_engine)
|
||||||
|
constrs = inspector.get_unique_constraints('build_requests')
|
||||||
|
constr_names = [constr['name'] for constr in constrs]
|
||||||
|
if 'uniq_build_requests0instance_uuid' not in constr_names:
|
||||||
|
UniqueConstraint('instance_uuid', table=build_requests,
|
||||||
|
name='uniq_build_requests0instance_uuid').create()
|
@@ -168,7 +168,10 @@ class BuildRequest(API_BASE):
|
|||||||
|
|
||||||
__tablename__ = 'build_requests'
|
__tablename__ = 'build_requests'
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
Index('build_requests_instance_uuid_idx', 'instance_uuid'),
|
||||||
Index('build_requests_project_id_idx', 'project_id'),
|
Index('build_requests_project_id_idx', 'project_id'),
|
||||||
|
schema.UniqueConstraint('instance_uuid',
|
||||||
|
name='uniq_build_requests0instance_uuid'),
|
||||||
schema.UniqueConstraint('request_spec_id',
|
schema.UniqueConstraint('request_spec_id',
|
||||||
name='uniq_build_requests0request_spec_id')
|
name='uniq_build_requests0request_spec_id')
|
||||||
)
|
)
|
||||||
@@ -180,6 +183,7 @@ class BuildRequest(API_BASE):
|
|||||||
foreign_keys=request_spec_id,
|
foreign_keys=request_spec_id,
|
||||||
back_populates='build_request',
|
back_populates='build_request',
|
||||||
primaryjoin=request_spec_id == RequestSpec.id)
|
primaryjoin=request_spec_id == RequestSpec.id)
|
||||||
|
instance_uuid = Column(String(36))
|
||||||
project_id = Column(String(255), nullable=False)
|
project_id = Column(String(255), nullable=False)
|
||||||
user_id = Column(String(255), nullable=False)
|
user_id = Column(String(255), nullable=False)
|
||||||
display_name = Column(String(255))
|
display_name = Column(String(255))
|
||||||
@@ -195,3 +199,4 @@ class BuildRequest(API_BASE):
|
|||||||
config_drive = Column(Boolean, default=False, nullable=False)
|
config_drive = Column(Boolean, default=False, nullable=False)
|
||||||
key_name = Column(String(255))
|
key_name = Column(String(255))
|
||||||
locked_by = Column(Enum('owner', 'admin'))
|
locked_by = Column(Enum('owner', 'admin'))
|
||||||
|
instance = Column(Text)
|
||||||
|
Reference in New Issue
Block a user