[PATCH 1 of 2 saem_ref] [ark] Add a "naan" column to ark table

Denis Laxalde denis.laxalde at logilab.fr
Fri Feb 16 12:26:35 CET 2018


Philippe Pepiot a écrit :
> On 16/02/2018, Denis Laxalde wrote:
>> # HG changeset patch
>> # User Denis Laxalde <denis.laxalde at logilab.fr>
>> # Date 1518517547 -3600
>> #      Tue Feb 13 11:25:47 2018 +0100
>> # Node ID ae9b438859eb66cd5a0edd29b5b98552c041f047
>> # Parent  4a200f4623e28e2729c07d23cf62772d852ca007
>> # Available At http://hg.logilab.org/review/cubes/saem_ref
>> #              hg pull http://hg.logilab.org/review/cubes/saem_ref -r ae9b438859eb
>> # EXP-Topic ark/naan
>> [ark] Add a "naan" column to ark table
>>
>> We actually need to ensure uniqueness of the whole ARK identifier
>> (including the "naan" part).
>>
>> The only needed change in test is in `unittest_entities.py` where we
>> changed the "what" value into a number as this is now required by schema
>> constraint.
>>
>> diff --git a/cubicweb_saem_ref/entities/__init__.py b/cubicweb_saem_ref/entities/__init__.py
>> --- a/cubicweb_saem_ref/entities/__init__.py
>> +++ b/cubicweb_saem_ref/entities/__init__.py
>> @@ -52,9 +52,10 @@ class ARKIdentifierGenerator(ARKIdentifi
>>  
>>      def assign_name(self):
>>          """Assign and return a new name part of the ARK identifier"""
>> +        naan = int(self.cw_extra_kwargs['naa_what'])
>>          cu = self._cw.system_sql(
>> -            'select * from gen_ark(%s, %s, %s);',
>> -            (ARK_NAME_LENGTH, ARK_PREFIX, ARK_CONTROLCHAR),
>> +            'select * from gen_ark(%s, %s, %s, %s);',
>> +            (naan, ARK_NAME_LENGTH, ARK_PREFIX, ARK_CONTROLCHAR),
>>          )
>>          ark_name, = cu.fetchone()
>>          return ark_name
>> @@ -77,18 +78,19 @@ class QualifiedARKIdentifierGenerator(AR
>>                  "ARK identifier for parent entity #%d looks malformattted: %s"
>>                  % (self.parent_entity.eid, self.parent_entity.ark)
>>              )
>> +        naan = int(self.cw_extra_kwargs['naa_what'])
>>          # Sanity check to make sure we're not producing ARK identifiers with
>>          # different NAAN for entities that are supposed to be parent of each
>>          # others.
>> -        if int(match.group('naan')) != int(self.cw_extra_kwargs['naa_what']):
>> +        if int(match.group('naan')) != naan:
>>              raise ValueError(
>>                  "NAAN of parent entity #%d does not match the value of 'naa_what' parameter: %s"
>>                  % (self.parent_entity.eid, self.cw_extra_kwargs['naa_what'])
>>              )
>>          name = match.group('name')
>>          cu = self._cw.system_sql(
>> -            'select * from gen_qualified_ark(%s, %s);',
>> -            (name, ARK_QUALIFIER_LENGTH, ),
>> +            'select * from gen_qualified_ark(%s, %s, %s);',
>> +            (naan, name, ARK_QUALIFIER_LENGTH),
>>          )
>>          ark_qualifier, = cu.fetchone()
>>          return u'/'.join([name, ark_qualifier])
>> diff --git a/cubicweb_saem_ref/schema/ark.postgres.sql b/cubicweb_saem_ref/schema/ark.postgres.sql
>> --- a/cubicweb_saem_ref/schema/ark.postgres.sql
>> +++ b/cubicweb_saem_ref/schema/ark.postgres.sql
>> @@ -1,7 +1,8 @@
>>  CREATE TABLE ark (
>> +    naan INTEGER NOT NULL,
>>      name TEXT NOT NULL,
>>      qualifier TEXT NOT NULL DEFAULT '',
>> -    CONSTRAINT qualified_name PRIMARY KEY (name, qualifier)
>> +    PRIMARY KEY (naan, name, qualifier)
> 
> Why you dropped the explicit name of the constraint ?
> Postgres will surely name it ark_pkey but there is no
> guarantee on this. Having an explicit name will simplify future
> migrations of the schema.

I dropped it because I did not use it and could not think of a
meaningful name. But I didn't know the impact of that change. Thanks.

By the way, I'm still not sure a primary key is useful over a unique
constraint. Do you have an opinion on this?



More information about the saem-devel mailing list