diff options
Diffstat (limited to 'nova/db')
-rw-r--r-- | nova/db/sqlalchemy/api.py | 3 | ||||
-rw-r--r-- | nova/db/sqlalchemy/models.py | 33 | ||||
-rw-r--r-- | nova/db/sqlalchemy/utils.py | 16 |
3 files changed, 36 insertions, 16 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 9e0f8f7e0..72c9fcefe 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -555,8 +555,7 @@ def compute_node_update(context, compute_id, values, prune_stats=False): # Always update this, even if there's going to be no other # changes in data. This ensures that we invalidate the # scheduler cache of compute node data in case of races. - if 'updated_at' not in values: - values['updated_at'] = timeutils.utcnow() + values['updated_at'] = timeutils.utcnow() convert_datetimes(values, 'created_at', 'deleted_at', 'updated_at') compute_ref.update(values) return compute_ref diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 183a42f60..d1be47f8c 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -760,11 +760,15 @@ class FloatingIp(BASE, NovaBase): class DNSDomain(BASE, NovaBase): """Represents a DNS domain with availability zone or project info.""" __tablename__ = 'dns_domains' + __table_args__ = ( + Index('project_id', 'project_id'), + Index('dns_domains_domain_deleted_idx', 'domain', 'deleted'), + ) deleted = Column(Boolean, default=False) - domain = Column(String(512), primary_key=True) - scope = Column(String(255)) - availability_zone = Column(String(255)) - project_id = Column(String(255)) + domain = Column(String(255), primary_key=True) + scope = Column(String(255), nullable=True) + availability_zone = Column(String(255), nullable=True) + project_id = Column(String(255), nullable=True) class ConsolePool(BASE, NovaBase): @@ -899,6 +903,9 @@ class AggregateHost(BASE, NovaBase): class AggregateMetadata(BASE, NovaBase): """Represents a metadata key/value pair for an aggregate.""" __tablename__ = 'aggregate_metadata' + __table_args__ = ( + Index('aggregate_metadata_key_idx', 'key'), + ) id = Column(Integer, primary_key=True) key = Column(String(255), nullable=False) value = Column(String(255), nullable=False) @@ -955,15 +962,19 @@ class AgentBuild(BASE, NovaBase): class BandwidthUsage(BASE, NovaBase): """Cache for instance bandwidth usage data pulled from the hypervisor.""" __tablename__ = 'bw_usage_cache' + __table_args__ = ( + Index('bw_usage_cache_uuid_start_period_idx', 'uuid', + 'start_period'), + ) id = Column(Integer, primary_key=True, nullable=False) - uuid = Column(String(36), nullable=False) - mac = Column(String(255), nullable=False) + uuid = Column(String(36), nullable=True) + mac = Column(String(255), nullable=True) start_period = Column(DateTime, nullable=False) - last_refreshed = Column(DateTime) - bw_in = Column(BigInteger) - bw_out = Column(BigInteger) - last_ctr_in = Column(BigInteger) - last_ctr_out = Column(BigInteger) + last_refreshed = Column(DateTime, nullable=True) + bw_in = Column(BigInteger, nullable=True) + bw_out = Column(BigInteger, nullable=True) + last_ctr_in = Column(BigInteger, nullable=True) + last_ctr_out = Column(BigInteger, nullable=True) class VolumeUsage(BASE, NovaBase): diff --git a/nova/db/sqlalchemy/utils.py b/nova/db/sqlalchemy/utils.py index 6c0a53846..918f50bfd 100644 --- a/nova/db/sqlalchemy/utils.py +++ b/nova/db/sqlalchemy/utils.py @@ -17,7 +17,7 @@ import re -from migrate.changeset import UniqueConstraint +from migrate.changeset import UniqueConstraint, ForeignKeyConstraint from sqlalchemy import Boolean from sqlalchemy import CheckConstraint from sqlalchemy import Column @@ -101,7 +101,8 @@ def _get_unique_constraints_in_sqlite(migrate_engine, table_name): uniques = set([ schema.UniqueConstraint( - *[getattr(table.c, c.strip()) for c in cols.split(",")], name=name + *[getattr(table.c, c.strip(' "')) + for c in cols.split(",")], name=name ) for name, cols in re.findall(regexp, sql_data) ]) @@ -128,7 +129,8 @@ def _drop_unique_constraint_in_sqlite(migrate_engine, table_name, uc_name, table.constraints.update(uniques) constraints = [constraint for constraint in table.constraints - if not constraint.name == uc_name] + if not constraint.name == uc_name and + not isinstance(constraint, schema.ForeignKeyConstraint)] new_table = Table(table_name + "__tmp__", meta, *(columns + constraints)) new_table.create() @@ -139,12 +141,20 @@ def _drop_unique_constraint_in_sqlite(migrate_engine, table_name, uc_name, indexes.append(Index(index["name"], *column_names, unique=index["unique"])) + f_keys = [] + for fk in insp.get_foreign_keys(table_name): + refcolumns = [fk['referred_table'] + '.' + col + for col in fk['referred_columns']] + f_keys.append(ForeignKeyConstraint(fk['constrained_columns'], + refcolumns, table=new_table, name=fk['name'])) ins = InsertFromSelect(new_table, table.select()) migrate_engine.execute(ins) table.drop() [index.create(migrate_engine) for index in indexes] + for fkey in f_keys: + fkey.create() new_table.rename(table_name) |