Skip to content

Understanding change

In part 1, we covered deleted data, and the fact that in an immutable database, data is never truly gone.

In this part, we’ll expand more on the idea of querying the timeline.

Let’s use a single record for this example.

Let’s pretend the first version is inserted on 2024-01-01.

2024-01-01
Run
Open in xt-fiddle

(Notice how we don’t have to create a database table explicitly, or tell our database about the columns - the database will learn the schema from the data we give it)

Let’s query this product:

Run
Open in xt-fiddle

A month later on 2024-02-01, we decide to update the price of the product.

2024-02-01
Run
Open in xt-fiddle

Let’s check the new price:

Run
Open in xt-fiddle

A month later on 2024-03-01, with part costs still increasing, we increase the price again.

2024-03-01
Run
Open in xt-fiddle

Let’s say we need to do an audit query, and we need to know the price of every product as of 2024-01-15.

Run
Open in xt-fiddle

Here you can see we have the correct historical price for 2024-01-15, which is 340

Now let’s say our CFO wants to know how the prices have increased over Q1?

Run
Open in xt-fiddle

When did the bicycle price first exceed $350 ?

Run
Open in xt-fiddle

Yes, it was the price change of 2024-02-01 where the bicycle’s price exceeded $350.

Conclusion

We’ve shown that it’s possible to view the past history of records in our database without creating any special views, audit tables or workarounds.

Let’s move ahead to part 3.