Audit Trail

An audit trail on your data is a record of every change made to every row. In Gyxi DB it is referred to as a History table.

All types have a special History table, which contains changes made to rows of this type. This table is required for technical purposes and cannot be removed.

You can access the history for a single item with a call as indicated in API Reference. However, it may not always return all results. History tables may be cleared without warning from time to time when they are not needed. Their data is made available to you as a courtesy only.

If you want a history table that you can depend on, the answer is the same as for almost any other question: Create a view.

The view you create should combine the partition and the id into the new partition. And then the id should be a timestamp (easiest) or version number (if your software manages such a number).

The view could look something like this:

{
“id”: “AccountHistory”,
  “sourceRegion”: “germany",
  “type”: “account”,
  “partitionBy”: “currentPartion+currentId”
  “idBy”: “changedTime”
}

Let’s take an example.

“person” type

partitionKey

id

userId

companyName

postalCode

saved

Northwind

1

1

Northwind

2500

2021-09-12 15:22

Northwind

2

2

Northwind

2500

2018-06-02 19:32

Acme

3

3

Acme

2500

2021-10-28 01:15


In this case, the “saved” property contains the timestamp for when this item was most recently saved.

Create a view with this definition and you can use “idBy” if you do not care about the order or if you want to look up specific items by their timestamp or version number. Or you can use “orderBy” as shown below to get the latest changes shown first, which is often natural in a History table.

{
“id”: “PersonHistory”,
“sourceRegion”: “germany",
“type”: “person”,
“partitionBy”: “companyName+userId”
“orderBy”: “saved”,
“orderByDescending”: true
}

It will result in a view that looks like this:

person > PersonHistory

partitionKey

id

userId

companyName

postalCode

saved

Northwind+1

2021-09-13 15:22

1

Northwind

2500

2021-09-13 15:22

Northwind+1

2021-09-12 11:12

1

Northwind

2500

2021-09-12 11:12

Northwind+2

2021-10-28 01:15

2

Northwind

2500

2021-10-28 01:15

 

Because the time an item is saved is, hopefully, unique, it will be saved as a new row every time and the History table can grow quite large. Even if there are no changes to the object, a new row will be saved because the “saved” timestamp is changed.

Keep in mind, that if you want to have a History table, you should create it as early as possible. You cannot go back in time and create a history table based on changes that has already happened.

Business Registration Number DK28916779  

Resources