diff options
author | Victor Sergeyev <vsergeyev@mirantis.com> | 2013-05-22 15:46:02 +0300 |
---|---|---|
committer | Victor Sergeyev <vsergeyev@mirantis.com> | 2013-06-07 18:09:51 +0300 |
commit | 64ce647003b110771331d3daf92980729bd3988e (patch) | |
tree | a1b82d44e55da9bc23f05a00953a2f4504d45f69 /nova/db/sqlalchemy/models.py | |
parent | 7a475d3cd606e68090075c1a8944e3aeb7898b87 (diff) | |
download | nova-64ce647003b110771331d3daf92980729bd3988e.tar.gz nova-64ce647003b110771331d3daf92980729bd3988e.tar.xz nova-64ce647003b110771331d3daf92980729bd3988e.zip |
Rename unique constraints due to new convention.
We have found that current constraint name convention allows us to create
constraints with duplicate names. It happens if we add constraints
in different tables with the same column names (for example, `name`,
`deleted`). In this case we can not create new constraint in mysql due to
database limitation (it requires constraint name to be unique within a
database). To solve this issue unique constraint name convention has
been changed from "uniq_c1_x_c2_x_c3" to "uniq_t0c10c20c3" where `t` is
a table name and columns `c1`, `c2`, `c3` are in UniqueConstraint.
Fixed unique constraints in models description.
Synced db code from oslo (function `_raise_if_duplicate_entry_error()`
modified respectively to new unique constraint name convention).
blueprint db-enforce-unique-keys
Fixes: bug 1182054
Change-Id: I4122dfb910a07a1a423781ebc22e9ce50596a05d
Diffstat (limited to 'nova/db/sqlalchemy/models.py')
-rw-r--r-- | nova/db/sqlalchemy/models.py | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index f10bc8c32..c4660226f 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -246,6 +246,10 @@ class InstanceInfoCache(BASE, NovaBase): Represents a cache of information about an instance """ __tablename__ = 'instance_info_caches' + __table_args__ = ( + schema.UniqueConstraint( + "instance_uuid", + name="uniq_instance_info_caches0instance_uuid"),) id = Column(Integer, primary_key=True, autoincrement=True) # text column used for storing a json object of network data for api @@ -262,6 +266,14 @@ class InstanceInfoCache(BASE, NovaBase): class InstanceTypes(BASE, NovaBase): """Represent possible instance_types or flavor of VM offered.""" __tablename__ = "instance_types" + + __table_args__ = ( + schema.UniqueConstraint("flavorid", "deleted", + name="uniq_instance_types0flavorid0deleted"), + schema.UniqueConstraint("name", "deleted", + name="uniq_instance_types0name0deleted") + ) + id = Column(Integer, primary_key=True) name = Column(String(255)) memory_mb = Column(Integer) @@ -552,7 +564,10 @@ class ProviderFirewallRule(BASE, NovaBase): class KeyPair(BASE, NovaBase): """Represents a public key pair for ssh.""" __tablename__ = 'key_pairs' - __table_args__ = (schema.UniqueConstraint("name", "user_id"), ) + __table_args__ = ( + schema.UniqueConstraint("name", "user_id", "deleted", + name="uniq_key_pairs0user_id0name0deleted"), + ) id = Column(Integer, primary_key=True) name = Column(String(255)) @@ -591,8 +606,11 @@ class Migration(BASE, NovaBase): class Network(BASE, NovaBase): """Represents a network.""" __tablename__ = 'networks' - __table_args__ = (schema.UniqueConstraint("vpn_public_address", - "vpn_public_port"), ) + __table_args__ = ( + schema.UniqueConstraint("vlan", "deleted", + name="uniq_networks0vlan0deleted"), + ) + id = Column(Integer, primary_key=True) label = Column(String(255)) @@ -628,6 +646,10 @@ class Network(BASE, NovaBase): class VirtualInterface(BASE, NovaBase): """Represents a virtual interface on an instance.""" __tablename__ = 'virtual_interfaces' + __table_args__ = ( + schema.UniqueConstraint("address", + name="unique_virtual_interfaces0address"), + ) id = Column(Integer, primary_key=True) address = Column(String(255), unique=True) network_id = Column(Integer, nullable=False) @@ -669,6 +691,10 @@ class FixedIp(BASE, NovaBase): class FloatingIp(BASE, NovaBase): """Represents a floating ip that dynamically forwards to a fixed ip.""" __tablename__ = 'floating_ips' + __table_args__ = ( + schema.UniqueConstraint("address", "deleted", + name="uniq_floating_ips0address0deleted"), + ) id = Column(Integer, primary_key=True) address = Column(types.IPAddress()) fixed_ip_id = Column(Integer, nullable=True) @@ -757,6 +783,11 @@ class InstanceSystemMetadata(BASE, NovaBase): class InstanceTypeProjects(BASE, NovaBase): """Represent projects associated instance_types.""" __tablename__ = "instance_type_projects" + __table_args__ = (schema.UniqueConstraint( + "instance_type_id", "project_id", "deleted", + name="uniq_instance_type_projects0instance_type_id0project_id0deleted" + ), + ) id = Column(Integer, primary_key=True) instance_type_id = Column(Integer, ForeignKey('instance_types.id'), nullable=False) @@ -983,6 +1014,12 @@ class InstanceIdMapping(BASE, NovaBase): class TaskLog(BASE, NovaBase): """Audit log for background periodic tasks.""" __tablename__ = 'task_log' + __table_args__ = ( + schema.UniqueConstraint( + 'task_name', 'host', 'period_beginning', 'period_ending', + name="uniq_task_log0task_name0host0period_beginning0period_ending" + ), + ) id = Column(Integer, primary_key=True, nullable=False, autoincrement=True) task_name = Column(String(255), nullable=False) state = Column(String(255), nullable=False) |