Package s3 :: Module s3merge :: Class S3RecordMerger
[frames] | no frames]

Class S3RecordMerger

source code

object --+
         |
        S3RecordMerger

Record Merger

Instance Methods
 
__init__(self, resource)
Constructor
source code
 
update_record(self, table, record_id, row, data) source code
 
delete_record(self, table, record_id, replaced_by=None) source code
 
merge_realms(self, table, original, duplicate)
Merge the realms of two person entities (update all realm_entities in all records from duplicate to original)
source code
 
fieldname(self, key) source code
 
merge(self, original_id, duplicate_id, replace=None, update=None, main=True)
Merge a duplicate record into its original and remove the duplicate, updating all references in the database.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
raise_error(msg, error=RuntimeError)
Roll back the current transaction and raise an error
source code
Properties

Inherited from object: __class__

Method Details

__init__(self, resource)
(Constructor)

source code 

Constructor

Parameters:
  • resource - the resource
Overrides: object.__init__

raise_error(msg, error=RuntimeError)
Static Method

source code 

Roll back the current transaction and raise an error

Parameters:
  • message - error message
  • error - exception class to raise

update_record(self, table, record_id, row, data)

source code 

delete_record(self, table, record_id, replaced_by=None)

source code 

merge_realms(self, table, original, duplicate)

source code 

Merge the realms of two person entities (update all realm_entities in all records from duplicate to original)

Parameters:
  • table - the table original and duplicate belong to
  • original - the original record
  • duplicate - the duplicate record

fieldname(self, key)

source code 

merge(self, original_id, duplicate_id, replace=None, update=None, main=True)

source code 

Merge a duplicate record into its original and remove the duplicate, updating all references in the database.

Parameters:
  • original_id - the ID of the original record
  • duplicate_id - the ID of the duplicate record
  • replace - list fields names for which to replace the values in the original record with the values of the duplicate
  • update - dict of {field:value} to update the final record
  • main - internal indicator for recursive calls

Status: work in progress

To Do: de-duplicate components and link table entries

Notes:
  • virtual references (i.e. non-SQL, without foreign key constraints) must be declared in the table configuration of the referenced table like:

    s3db.configure(tablename, referenced_by=[(tablename, fieldname)])

    This does not apply for list:references which will be found automatically.

  • this method can only be run from master resources (in order to find all components). To merge component records, you have to re-define the component as a master resource.
  • CLI calls must db.commit()