Skip to content

Commit

Permalink
Merge pull request #30 from CloverHealth/converge-models
Browse files Browse the repository at this point in the history
Converge models
  • Loading branch information
multigl authored Jul 20, 2017
2 parents 426b303 + 1233122 commit 9c870f3
Show file tree
Hide file tree
Showing 13 changed files with 355 additions and 446 deletions.
6 changes: 4 additions & 2 deletions temporal_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from .version import __version__
from .bases import (
Clocked,
ClockedOption,
TemporalOption,
EntityClock,
TemporalProperty,
TemporalActivityMixin)
from .session import temporal_session, persist_history, is_temporal_session
from .clock import add_clock, get_activity_clock_backref, get_history_model, get_history_model
from .clock import add_clock
from .util import get_activity_clock_backref, \
get_history_model
from .core import TemporalModel
16 changes: 9 additions & 7 deletions temporal_sqlalchemy/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from temporal_sqlalchemy import nine
from temporal_sqlalchemy.metadata import get_session_metadata


_ClockSet = collections.namedtuple('_ClockSet', ('effective', 'vclock'))

T_PROPS = typing.TypeVar(
Expand All @@ -25,7 +24,8 @@
class EntityClock(object):
id = sa.Column(sap.UUID(as_uuid=True), default=uuid.uuid4, primary_key=True)
tick = sa.Column(sa.Integer, nullable=False)
timestamp = sa.Column(sa.DateTime(True), server_default=sa.func.current_timestamp())
timestamp = sa.Column(sa.DateTime(True),
server_default=sa.func.current_timestamp())


class TemporalProperty(object):
Expand All @@ -38,12 +38,12 @@ class TemporalProperty(object):


class TemporalActivityMixin(object):
@abc.abstractproperty
@abc.abstractmethod
def id(self):
pass


class ClockedOption(object):
class TemporalOption(object):
def __init__(
self,
history_models: typing.Dict[T_PROPS, nine.Type[TemporalProperty]],
Expand All @@ -59,14 +59,14 @@ def __init__(
@property
def clock_table(self):
warnings.warn(
'use ClockedOption.clock_model instead',
'use TemporalOption.clock_model instead',
PendingDeprecationWarning)
return self.clock_model

@property
def history_tables(self):
warnings.warn(
'use ClockedOption.history_models instead',
'use TemporalOption.history_models instead',
PendingDeprecationWarning)
return self.history_models

Expand Down Expand Up @@ -180,7 +180,7 @@ class Clocked(object):
vclock = sa.Column(sa.Integer, default=1)

clock = None # type: orm.relationship
temporal_options = None # type: ClockedOption
temporal_options = None # type: TemporalOption
first_tick = None # type: EntityClock
latest_tick = None # type: EntityClock

Expand All @@ -194,6 +194,8 @@ def date_modified(self):

@contextlib.contextmanager
def clock_tick(self, activity: TemporalActivityMixin = None):
warnings.warn("clock_tick is going away in 0.5.0",
PendingDeprecationWarning)
"""Increments vclock by 1 with changes scoped to the session"""
if self.temporal_options.activity_cls is not None and activity is None:
raise ValueError("activity is missing on edit") from None
Expand Down
Loading

0 comments on commit 9c870f3

Please sign in to comment.