Merge pull request #10 from FlipsideCrypto/add/post-hook-reorg

add/post-hook-update
This commit is contained in:
drethereum 2023-10-05 09:34:10 -06:00 committed by GitHub
commit 8bbad1211a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,30 +62,34 @@ WHERE
)
{% endmacro %}
{% macro block_reorg(target, hours) %}
DELETE
FROM
{{ target }}
t
WHERE
t._inserted_timestamp > DATEADD(
'hour',
-{{ hours}},
SYSDATE()
)
AND NOT EXISTS (
SELECT
1
FROM
{{ ref('silver__transactions') }}
s
WHERE
s._inserted_timestamp > DATEADD(
'hour',
-{{ hours}},
SYSDATE()
)
AND s.block_number = t.block_number
AND s.tx_hash = t.tx_hash
);
{% macro block_reorg(reorg_model_list, hours) %}
{% set models = reorg_model_list.split(",") %}
{% for model in models %}
{% set sql %}
DELETE FROM
{{ ref(model) }}
WHERE
_inserted_timestamp > DATEADD(
'hour',
-{{ hours }},
SYSDATE()
)
AND NOT EXISTS (
SELECT
1
FROM
{{ ref('silver__transactions') }}
WHERE
_inserted_timestamp > DATEADD(
'hour',
-{{ hours }},
SYSDATE()
)
AND block_number = block_number
AND tx_hash = tx_hash
);
{% endset %}
{% do run_query(sql) %}
{% endfor %}
{% endmacro %}