Changeset a32753a in rattail-corepos


Ignore:
Timestamp:
07/09/20 17:01:23 (5 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
9f3cfa0
Parents:
6ce4b59
Message:

Let CORE-POS datasync watcher use alternate "changes" table name

i needed this for sake of online demo, so that 2 separate rattail apps could
both watch the same CORE DB simultaneously

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail_corepos/datasync/corepos.py

    r6ce4b59 ra32753a  
    2525"""
    2626
     27import sqlalchemy as sa
     28
    2729from corepos.db.office_op import Session as CoreSession, model as corepos
    2830
     
    3739    prunes_changes = True
    3840
     41    def __init__(self, *args, **kwargs):
     42        super(CoreOfficeOpWatcher, self).__init__(*args, **kwargs)
     43
     44        self.changes_table_name = kwargs.get('changes_table_name',
     45                                             'datasync_changes')
     46
     47        self.corepos_metadata = sa.MetaData()
     48        self.corepos_changes = sa.Table(
     49            self.changes_table_name, self.corepos_metadata,
     50            sa.Column('id', sa.Integer(), nullable=False, primary_key=True),
     51            sa.Column('object_type', sa.String(length=255), nullable=False),
     52            sa.Column('object_key', sa.String(length=255), nullable=False),
     53            sa.Column('deleted', sa.Boolean(), nullable=False, default=False))
     54
    3955    def get_changes(self, lastrun):
    4056        session = CoreSession()
    41         changes = session.query(corepos.Change).all()
    42         session.expunge_all()
     57        result = session.execute(sa.sql.select([self.corepos_changes]))
     58        changes = result.fetchall()
    4359        session.close()
    4460        if changes:
     
    5571        session = CoreSession()
    5672        for key in keys:
    57             change = session.query(corepos.Change).get(key)
    58             if change:
    59                 session.delete(change)
    60                 session.flush()
     73            result = session.execute(self.corepos_changes.select()\
     74                                     .where(self.corepos_changes.c.id == key))
     75            if result.fetchall():
     76                session.execute(self.corepos_changes.delete()\
     77                                .where(self.corepos_changes.c.id == key))
    6178                deleted += 1
    6279        session.commit()
Note: See TracChangeset for help on using the changeset viewer.