Implementing real-world code and business rules
In this section, we will provide many samples of real-life code, replacing the initial sample code with real project code and implementing some business logic, known as business rules, and adding some extra data, showing you how the changes are stored.
Replacing snapshots with HIST tables
The first thing that we want to do is replace the snapshots that we used to store the changes in the incoming data with the HIST tables that we introduced in the previous chapter.
First, we will replace the SNSH_ABC_BANK_POSITION
snapshot with the HIST_ABC_BANK_POSITION
table in the REF_POSITION_ABC_BANK
model:
- Create a new file named
HIST_ABC_BANK_POSITION
in the staging folder and add the following code:{{ save_history(
    input_rel = ref('STG_ABC_BANK_POSITION'),
    key_column = 'POSITION_HKEY',
    diff_column = 'POSITION_HDIFF',
) }}
We...