def after_table(self):
        entity = self.entity
        version_colname, timestamp_colname = \
            entity.__versioned_column_names__

        # look for events
        after_revert_events = []
        for name, func in getmembers(entity, inspect.ismethod):
            if getattr(func, '_elixir_after_revert', False):
                after_revert_events.append(func)

        # create a history table for the entity
        skipped_columns = [version_colname]
        if self.check_concurrent:
            skipped_columns.append('concurrent_version')

        columns = [
            column.copy() for column in entity.table.c
            if column.name not in skipped_columns
        ]
        columns.append(Column(version_colname, Integer, primary_key=True))
        table = Table(entity.table.name + '_history', entity.table.metadata,
            *columns
        )
        entity.__history_table__ = table

        # create an object that represents a version of this entity
        class Version(object):
            pass

        # map the version class to the history table for this entity
        Version.__name__ = entity.__name__ + 'Version'
        Version.__versioned_entity__ = entity
        mapper(Version, entity.__history_table__)

        version_col = getattr(table.c, version_colname)
        timestamp_col = getattr(table.c, timestamp_colname)

        # attach utility methods and properties to the entity
        def get_versions(self):
            v = object_session(self).query(Version) \
                                    .filter(get_history_where(self)) \
                                    .order_by(version_col) \
                                    .all()
            # history contains all the previous records.
            # Add the current one to the list to get all the versions
            v.append(self)
            return v

        def get_as_of(self, dt):
            # if the passed in timestamp is older than our current version's
            # time stamp, then the most recent version is our current version
            if getattr(self, timestamp_colname) < dt:
                return self

            # otherwise, we need to look to the history table to get our
            # older version
            sess = object_session(self)
            query = sess.query(Version) \
                        .filter(and_(get_history_where(self),
                                     timestamp_col <= dt)) \
                        .order_by(desc(timestamp_col)).limit(1)
            return query.first()

        def revert_to(self, to_version):
            if isinstance(to_version, Version):
                to_version = getattr(to_version, version_colname)

            old_version = table.select(and_(
                get_history_where(self),
                version_col == to_version
            )).execute().fetchone()

            entity.table.update(get_entity_where(self)).execute(
                dict(old_version.items())
            )

            table.delete(and_(get_history_where(self),
                              version_col >= to_version)).execute()
            self.expire()
            for event in after_revert_events:
                event(self)

        def revert(self):
            assert getattr(self, version_colname) > 1
            self.revert_to(getattr(self, version_colname) - 1)

        def compare_with(self, version):
            differences = {}
            for column in self.table.c:
                if (version_colname, 'concurrent_version') in column.name:
                    continue
                this = getattr(self, column.name)
                that = getattr(version, column.name)
                if this != that:
                    differences[column.name] = (this, that)
            return differences

        entity.versions = property(get_versions)
        entity.get_as_of = get_as_of
        entity.revert_to = revert_to
        entity.revert = revert
        entity.compare_with = compare_with
        Version.compare_with = compare_with
dataset/ETHPy150Open jmg/elixir/elixir/ext/versioned.py/VersionedEntityBuilder.after_table/swapped operands of `in`