Fix autogenerated db migrations

This trys to fix the inconsistent between database and models.

[alembic.autogenerate.compare]:
* Detected removed index 'uniq_compute_node0rp_uuid' on 'compute_node'
* Detected added foreign key (capsule_id)(id) on table container
* Detected added unique constraint 'uniq_image0repotag' on '['repo', 'tag']'
* Detected removed index 'uniq_image0repotaghost' on 'image'
* Detected NULL on column 'quota_usages.resource'
* Detected added index 'ix_quota_usages_resource' on '['resource']'
* Detected NULL on column 'registry.domain'

Change-Id: I2a0aad5e863466230602141b669e6d1cab0e9221
This commit is contained in:
Zhenguo Niu 2020-03-27 02:52:19 +00:00
parent 05312bdd20
commit 33b96a81a7
6 changed files with 48 additions and 6 deletions

View File

@ -0,0 +1,35 @@
# 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.
"""add-missing-index-and-foreign-key
Revision ID: 74c97dca93d0
Revises: 47d79ffdc582
Create Date: 2020-03-27 02:51:30.959226
"""
# revision identifiers, used by Alembic.
revision = '74c97dca93d0'
down_revision = '47d79ffdc582'
branch_labels = None
depends_on = None
from alembic import op
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('container', schema=None) as batch_op:
batch_op.create_foreign_key(
None, 'container', ['capsule_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###

View File

@ -259,7 +259,8 @@ class Image(Base):
__tablename__ = 'image'
__table_args__ = (
schema.UniqueConstraint('repo', 'tag', name='uniq_image0repotag'),
schema.UniqueConstraint(
'repo', 'tag', 'host', name='uniq_image0repotaghost'),
table_args()
)
id = Column(Integer, primary_key=True)
@ -366,6 +367,7 @@ class ComputeNode(Base):
__tablename__ = 'compute_node'
__table_args__ = (
schema.UniqueConstraint('rp_uuid', name='uniq_compute_node0rp_uuid'),
table_args()
)
uuid = Column(String(36), primary_key=True, nullable=False)
@ -540,7 +542,7 @@ class QuotaUsage(Base):
id = Column(Integer, primary_key=True)
project_id = Column(String(255), index=True)
resource = Column(String(255), index=True)
resource = Column(String(255), nullable=False)
in_use = Column(Integer, nullable=False)
reserved = Column(Integer, nullable=False)
@ -584,6 +586,6 @@ class Registry(Base):
user_id = Column(String(255))
uuid = Column(String(36))
name = Column(String(255))
domain = Column(String(255))
domain = Column(String(255), nullable=False)
username = Column(String(255))
password = Column(String(255))

View File

@ -31,7 +31,7 @@ class Registry(base.ZunPersistentObject, base.ZunObject):
'name': fields.StringField(nullable=True),
'project_id': fields.StringField(nullable=True),
'user_id': fields.StringField(nullable=True),
'domain': fields.StringField(nullable=True),
'domain': fields.StringField(nullable=False),
'username': fields.StringField(nullable=True),
'password': fields.StringField(nullable=True),
}

View File

@ -53,7 +53,8 @@ class TestHostController(api_base.FunctionalTest):
for id_ in range(4):
test_host = utils.create_test_compute_node(
context=self.context,
uuid=uuidutils.generate_uuid())
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid())
numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
test_host['numa_topology'] = numat
host = objects.ComputeNode(self.context, **test_host)

View File

@ -65,6 +65,7 @@ class DbComputeNodeTestCase(base.DbTestCase):
for i in range(1, 6):
node = utils.create_test_compute_node(
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid(),
context=self.context,
hostname='node' + str(i))
uuids.append(six.text_type(node['uuid']))
@ -77,6 +78,7 @@ class DbComputeNodeTestCase(base.DbTestCase):
for i in range(5):
node = utils.create_test_compute_node(
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid(),
context=self.context,
hostname='node' + str(i))
uuids.append(six.text_type(node.uuid))
@ -93,10 +95,12 @@ class DbComputeNodeTestCase(base.DbTestCase):
node1 = utils.create_test_compute_node(
hostname='node-one',
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid(),
context=self.context)
node2 = utils.create_test_compute_node(
hostname='node-two',
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid(),
context=self.context)
res = dbapi.list_compute_nodes(

View File

@ -370,7 +370,7 @@ object_data = {
'ContainerActionEvent': '1.0-2974d0a6f5d4821fd4e223a88c10181a',
'ZunNetwork': '1.1-26e8d37a54e5fc905ede657744a221d9',
'ExecInstance': '1.0-59464e7b96db847c0abb1e96d3cec30a',
'Registry': '1.0-36c2053fbc30e0021630e657dd1699c9',
'Registry': '1.0-9fddfae03f3ca052cc26c924642b9268',
'RequestGroup': '1.0-5e08d68d0a63b729778340d608ec4eae',
}