From 28191baa2b1a65fb86bbbbfc0974495059db6d42 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Mon, 24 Dec 2012 15:19:28 +0400 Subject: Provide creating real unique constraints for columns Main issue is that we can't create unique constraint for columns, because we are using soft deletion of entries (set `deleted` column to True). The main idea is to use `deleted` columns to create unique constraint for columns. For example (`col1`, `deleted`). To make (`col1`, `deleted`) unique after entry deletion, we should assign the value of `id` to `deleted` column. Change type of `deleted` column from Boolean to table.id.type for all tables. Change models.soft_delete() method to assign table.id instead of True to `deleted` column. Change query.soft_delete() method to assign literal_column("id") instead of True Change in db.models all occurrences of Table.deleted == False => Table.deleted == correct_type (0 or "") Value of `deleted` property of entries is used in public nova api. To keep API as is, we should change XMLDictSerializer by converting the type of `deleted` property to string representation of boolean. Change db.api.model_query() method to make it work with different types of `deleted` column. If we are using as model that is not subclass of NovaBase we should set parameter base_model as subclass of NovaBase that corresponds to model. Change in db.api all occurrences of using model_query with model that is not subclass of NovaBase. blueprint db-unique-keys Change-Id: Ie1f67f49a5d085e6371efb63fc23a1c8b25d9464 --- nova/api/openstack/wsgi.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nova/api') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 733685b14..8b593d742 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -406,6 +406,8 @@ class XMLDictSerializer(DictSerializer): if k in attrs: result.setAttribute(k, str(v)) else: + if k == "deleted": + v = str(bool(v)) node = self._to_xml_node(doc, metadata, k, v) result.appendChild(node) else: -- cgit