rattail.db.changes

Data Changes Interface

class rattail.db.changes.ChangeRecorder(config)[source]

Listener for session before_flush events.

This class is responsible for adding stub records to the changes table, which will in turn be used by the database synchronizer to manage change data propagation.

ensure_uuid(instance)[source]

Ensure the given instance has a UUID value.

This uses the following logic:

  • If the instance already has a UUID, nothing will be done.

  • If the instance contains a foreign key to another table, then that relationship will be traversed and the foreign object’s UUID will be used to populate that of the instance.

  • Otherwise, a new UUID will be generated for the instance.

ignore_object(obj)[source]

Return True if changes for the given object should be ignored.

is_deletable_orphan(instance)[source]

Determine if an object is an orphan and pending deletion.

process_deleted_object(session, obj)[source]

Record changes as appropriate, for the given ‘deleted’ object.

process_dirty_object(session, obj)[source]

Record changes as appropriate, for the given ‘dirty’ object.

process_new_object(session, obj)[source]

Record changes as appropriate, for the given ‘new’ object.

record_change(session, quiet=False, **kwargs)[source]

Record a change, by creating a new change record in the session.

record_rattail_change(session, instance, type_='dirty')[source]

Record a change record in the database.

If instance represents a change in which we are interested, then this method will create (or update) a rattail.db.model.Change record.

Returns:

True if a change was recorded, or False if it was ignored.

rattail.db.changes.record_changes(session, recorder=None, config=None)[source]

Record all relevant data changes which occur within a session.

Parameters:

session – A sqlalchemy.orm.session.Session class, or instance thereof.