From 8b47458193d124d718afc2b615b9260df7445432 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Sat, 8 Jun 2013 12:43:44 +0400 Subject: Fix db.models.ComputeNodeStats description DB models definition should be up-to-date with DB schema obtained after applying of migrations. Currently, there are no tests enforcing this and it's really hard to analyze what indexes should be added, and what indexes we have at the moment. So the first step is it to fix all models, and add missing descriptions about Indexes and UniqueConstraints in __table_args__ and use explicit 'nullable' parameter in columns description. Add missing 'nullable' parameters to all Columns Add empty __table_args__ parameter to Table Add 2 missing indexes in ComputeNodeStats model definition. blueprint db-sync-models-with-migrations Change-Id: I10761a6c1b32a457c855aff9603bf2edec44de17 --- nova/db/sqlalchemy/models.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index d52f68740..647c548c1 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -21,7 +21,7 @@ SQLAlchemy models for nova data. """ -from sqlalchemy import Column, Integer, BigInteger, String, schema +from sqlalchemy import Column, Index, Integer, BigInteger, String, schema from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import ForeignKey, DateTime, Boolean, Text, Float from sqlalchemy.orm import relationship, backref, object_mapper @@ -105,10 +105,17 @@ class ComputeNodeStat(BASE, NovaBase): """Stats related to the current workload of a compute host that are intended to aid in making scheduler decisions.""" __tablename__ = 'compute_node_stats' + __table_args__ = ( + Index('ix_compute_node_stats_compute_node_id', 'compute_node_id'), + Index('compute_node_stats_node_id_and_deleted_idx', + 'compute_node_id', 'deleted') + ) + id = Column(Integer, primary_key=True) - key = Column(String(511)) - value = Column(String(255)) - compute_node_id = Column(Integer, ForeignKey('compute_nodes.id')) + key = Column(String(511), nullable=False) + value = Column(String(255), nullable=False) + compute_node_id = Column(Integer, ForeignKey('compute_nodes.id'), + nullable=False) primary_join = ('and_(ComputeNodeStat.compute_node_id == ' 'ComputeNode.id, ComputeNodeStat.deleted == 0)') -- cgit