summaryrefslogtreecommitdiffstats
path: root/nova/openstack
diff options
context:
space:
mode:
authorVictor Sergeyev <vsergeyev@mirantis.com>2013-05-22 15:46:02 +0300
committerVictor Sergeyev <vsergeyev@mirantis.com>2013-06-07 18:09:51 +0300
commit64ce647003b110771331d3daf92980729bd3988e (patch)
treea1b82d44e55da9bc23f05a00953a2f4504d45f69 /nova/openstack
parent7a475d3cd606e68090075c1a8944e3aeb7898b87 (diff)
downloadnova-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/openstack')
-rw-r--r--nova/openstack/common/db/sqlalchemy/session.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/nova/openstack/common/db/sqlalchemy/session.py b/nova/openstack/common/db/sqlalchemy/session.py
index a3f4283d0..093d8b082 100644
--- a/nova/openstack/common/db/sqlalchemy/session.py
+++ b/nova/openstack/common/db/sqlalchemy/session.py
@@ -386,14 +386,15 @@ def _raise_if_duplicate_entry_error(integrity_error, engine_name):
"""
def get_columns_from_uniq_cons_or_name(columns):
- # note(boris-42): UniqueConstraint name convention: "uniq_c1_x_c2_x_c3"
- # means that columns c1, c2, c3 are in UniqueConstraint.
+ # note(vsergeyev): UniqueConstraint name convention: "uniq_t0c10c2"
+ # where `t` it is table name, `0` it is delimiter and
+ # columns `c1`, `c2` are in UniqueConstraint.
uniqbase = "uniq_"
if not columns.startswith(uniqbase):
if engine_name == "postgresql":
return [columns[columns.index("_") + 1:columns.rindex("_")]]
return [columns]
- return columns[len(uniqbase):].split("_x_")
+ return columns[len(uniqbase):].split("0")[1:]
if engine_name not in ["mysql", "sqlite", "postgresql"]:
return