-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
..._transaction_service/history/migrations/0027_remove_errored_internal_txs_20201112_1547.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 3.1.3 on 2020-11-12 15:47 | ||
|
||
from django.db import migrations | ||
from django.db.migrations import RunPython | ||
from django.db.models.expressions import F, OuterRef, RawSQL, Subquery | ||
|
||
|
||
def delete_errored_internal_txs(apps, schema_editor): | ||
""" | ||
Previously all traces were stored, even the errored ones. This method will delete old errored traces still present | ||
on the database | ||
:param apps: | ||
:param schema_editor: | ||
:return: | ||
""" | ||
InternalTx = apps.get_model('history', 'InternalTx') | ||
|
||
parent_errored_query = InternalTx.objects.annotate( | ||
child_trace_address=RawSQL('"history_internaltx"."trace_address"', tuple()) | ||
# Django bug, so we use RawSQL instead of: child_trace_address=OuterRef('trace_address') | ||
).filter( | ||
child_trace_address__startswith=F('trace_address'), | ||
ethereum_tx=OuterRef('ethereum_tx'), | ||
).exclude( | ||
error=None | ||
) | ||
|
||
InternalTx.objects.annotate( | ||
parent_errored=Subquery(parent_errored_query.values('pk')[:1]) | ||
).exclude( | ||
parent_errored=None, | ||
).delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('history', '0026_auto_20201030_1355'), | ||
] | ||
|
||
operations = [ | ||
RunPython(delete_errored_internal_txs) | ||
] |