[schema] add a unique index on cwuri

Closes #4985752

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset88577b10b31e
branchdefault
phasepublic
hiddenno
parent revision#480187dd66b3 [web] move AbstractAuthManager near its immediate concrete subclass
child revision#f4adc592ab59 Add requirements{,-test}.txt files, #b9c020b0de5d [js] add commonjs support, #e0c2c30770a8 [test] Skip spa2rql tests when fyzz is not available, #eeb0a9f08a76 [dataimport] Backport skos.dataimport to dataimport.importer., #ccaac943b0d3 Add new migration script to install db addons before schema init., #9a6e2fc4aa0a [server] Do not use progress bar when stdout is not a TTY, #699e49d76334 [wf] Fix Workflow.replace_state(), #70745a32a217 [server] Do not use progress bar when stdout is not a TTY, #689de42a81b9 [server] Do not use progress bar when stdout is not a TTY, #a88cf14c7af5 Add requirements{,-test}.txt files, #16376eb8b8e4 [test] Skip spa2rql tests when fyzz is not available, #ceb98787dfb1 Add new migration script to install db addons before schema init., #b7f48c8d6ec1 add a new install_db_addons migration event/script, giving the opportunity to install database extensions (eg languages and types), #6e8ae204bf00 Add requirements{,-test}.txt files, #eb6a4d3de1c1 Add requirements{,-test}.txt files, #d64fc3f16639 [dataimport] Backport skos.dataimport to dataimport.importer., #805a472d4ebe [dataimport] Backport skos.dataimport to dataimport.importer., #c3a717a46332 [dataimport] Backport skos.dataimport to dataimport.importer., #d008d9cac678 [dataimport] Backport skos.dataimport to dataimport.importer., #0a53c0685801 [dataimport] Backport skos.dataimport to dataimport.importer., #2d8eb37c6577 [dataimport] Backport skos.dataimport to dataimport.importer.
files modified by this revision
entity.py
misc/migration/3.21.0_Any.py
schemas/base.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1424856821 -3600
# Wed Feb 25 10:33:41 2015 +0100
# Node ID 88577b10b31ec288db40df772bad7c7f1dc0b3c7
# Parent 480187dd66b3c5b0eebe922e9cba8d4f3a34efaa
[schema] add a unique index on cwuri

Closes #4985752

diff --git a/entity.py b/entity.py
@@ -423,11 +423,11 @@
1              mainattr = cls.rest_attr
2              needcheck = not cls.e_schema.has_unique_values(mainattr)
3          else:
4              for rschema in cls.e_schema.subject_relations():
5                  if (rschema.final
6 -                    and rschema != 'eid'
7 +                    and rschema not in ('eid', 'cwuri')
8                      and cls.e_schema.has_unique_values(rschema)
9                      and cls.e_schema.rdef(rschema.type).cardinality[0] == '1'):
10                      mainattr = str(rschema)
11                      needcheck = False
12                      break
diff --git a/misc/migration/3.21.0_Any.py b/misc/migration/3.21.0_Any.py
@@ -17,5 +17,7 @@
13  sql('DELETE FROM entities WHERE eid < 0')
14 
15  commit()
16 
17  sync_schema_props_perms('CWEType')
18 +
19 +sync_schema_props_perms('cwuri')
diff --git a/schemas/base.py b/schemas/base.py
@@ -21,11 +21,11 @@
20  _ = unicode
21 
22  from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
23                              SubjectRelation,
24                              String, TZDatetime, Datetime, Password, Interval,
25 -                            Boolean)
26 +                            Boolean, UniqueConstraint)
27  from cubicweb.schema import (
28      RQLConstraint, WorkflowableEntityType, ERQLExpression, RRQLExpression,
29      PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS, PUB_SYSTEM_ATTR_PERMS)
30 
31  class CWUser(WorkflowableEntityType):
@@ -162,10 +162,11 @@
32      """internal entity uri"""
33      __permissions__ = PUB_SYSTEM_ATTR_PERMS
34      cardinality = '11'
35      subject = '*'
36      object = 'String'
37 +    constraints = [UniqueConstraint()]
38 
39 
40  # XXX find a better relation name
41  class for_user(RelationType):
42      """link a property to the user which want this property customization. Unless
@@ -181,11 +182,10 @@
43      object = 'CWUser'
44      composite = 'object'
45      cardinality = '?*'
46 
47 
48 -
49  class ExternalUri(EntityType):
50      """a URI representing an object in external data store"""
51      uri = String(required=True, unique=True, maxsize=256,
52                   description=_('the URI of the object'))
53