History operations save a permanent record of changes from one table into another. The operations can save old values, new values, and changes to values.
A history operations requires you to define both the source table and the destination table. You then define the history operation on the parent table.
The following example shows all options:
table orders:
module: ordering
description: Orders
column order_id:
primary_key: Y
uisearch: Y
column amt_lines:
suffix: _lines
auto:sum,orderlines.amt_line
history orderhistory:
table_id_dest: orders_hist
column order_id:
retcol: order_id
column amt_lines_old:
retold: amt_lines
column amt_lines_new:
retnew: amt_lines
column amt_lines_diff:
retdiff: amt_lines
require_dif: Y
table orderhistory:
module: ordering
description: Orders History
# All tables need a primary key, but the pk is
# not very meaningful on a history table, so
# just use Andromeda's pre-defined recnum column.
column recnum:
primary_key: Y
column order:
column amt_lines_old:
suffix: _lines_old
column amt_lines_new:
suffix: _lines_new
column amt_lines_diff:
suffix: _lines_diff
Now let us examine the HISTORY definition:
The precise behavior of retcol, retnew, retold and retdiff is:
| Property | Returns on Insert | Returns on Update | Returns on Delete |
|---|---|---|---|
| retcol | New Value | New Value | Old Value |
| retold | Old Value | Old Value | |
| retnew | New Value | New Value | |
| retdiff | New Value | New Value - Old Value | 0 - Old Value |
It is often very useful to add the pre-defined columns ts_ins and uid_ins to history tables. These record a timestamp of the change and ther user who made the change.