Does @db(versionHistory=true) work for Cassandra (TimedDataPoint) Types?

#1

I’m trying to enable this for debugging purposes, following the instructions here: Get specific version of an object

Here’s my type:

@db(compactType=true,
    datastore='cassandra',
    partitionKeyField='parent',
    persistenceOrder='start,descending(dataVersion)',
    persistDuplicates=false,
    shortId=true,
    shortIdReservationRange=100000,
    unique=['parent,start'], 
    versionHistory=true)
remix type RiskScore

I created and then modified a RiskScore, giving it a version of 2:

{
  "type": "RiskScore",
  "value": 0.0005,
  "id": "ABC125#G",
  "version": 2,
  "parent": {
    "id": "ABC125.Risk"
  },
  "start": "2018-07-26T00:00:00.000"
}

Then, trying to retrieve its first version:

RiskScore.make({id:"ABC125#G", meta:{getVersion:1}}).get(), gives me a 500 error with the message “Version 1 not found for object of type ‘RiskScore’ with id ‘ABC125#G’”

c3Grid(RiskScore.fetch({include: "this, versionEdits"})) doesn’t yield any version history either.

Am I trying to do something unsupported, or just making a mistake somewhere?

0 Likes

#2

I would set persistDuplicates to true in the db annotation and

RiskScore.create(RiskScore.make({parent: {id: “foo”}, start: “2018-01-01”, dataVersion: 1, value: 1}))
RiskScore.create(RiskScore.make({parent: {id: “foo”}, start: “2018-01-01”, dataVersion: 2, value: 2}))

c3Grid(RiskScore.fetch()) --> you would get 2 objects
c3Grid(RiskScore.fetch({filter: “parent.id == ‘foo’ && dataVersion == 1”})) --> you would get one object

@rohit.sureka is there another way of doing this?

1 Like

#3

Thanks @romain.juban, that provides the functionality I need.

Just to document a couple things further:

  • Setting compactType to false causes your record to get the meta field, providing created/updated timestamps if you need them (but enabled this on a timeseries type would be inefficient).
  • The versionHistory option doesn’t seem to work on this Type, however I haven’t tried it on a non-Cassandra Type to verify if that’s the cause.
0 Likes