add new database fields and migrate the data

This commit is contained in:
2021-05-11 07:35:56 +02:00
parent 2575e1e1d1
commit 5ac5f1c2d7
3 changed files with 86 additions and 1 deletions
@@ -0,0 +1,38 @@
# Generated by Django 3.2.2 on 2021-05-11 05:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('transactions', '0002_transaction_trade_id'),
]
operations = [
migrations.AddField(
model_name='transaction',
name='crypto_amount',
field=models.DecimalField(blank=True, decimal_places=10, max_digits=24, null=True),
),
migrations.AddField(
model_name='transaction',
name='crypto_fee',
field=models.DecimalField(blank=True, decimal_places=10, max_digits=24, null=True),
),
migrations.AddField(
model_name='transaction',
name='fiat_amount',
field=models.DecimalField(blank=True, decimal_places=10, max_digits=24, null=True),
),
migrations.AddField(
model_name='transaction',
name='fiat_fee',
field=models.DecimalField(blank=True, decimal_places=10, max_digits=24, null=True),
),
migrations.AddField(
model_name='transaction',
name='transaction_type',
field=models.CharField(choices=[('B', 'Buy Crypto'), ('S', 'Sell Crypto'), ('T', 'Transfer Crypto')], default='B', max_length=1),
),
]
@@ -0,0 +1,35 @@
# Generated by Django 3.2 on 2021-05-11 05:03
from django.db import migrations
def separate_fees(apps, schema_editor):
Person = apps.get_model('transactions', 'Transaction')
for tr in Transaction.objects.all():
if tr.amount_before_fee > 0:
tr.crypto_fee = tr.amount_before_fee - tr.amount_after_fee
tr.crypto_amount = tr.amount_before_fee
tr.transaction_type = 'B'
elif tr.amount_before_fee < 0:
tr.crypto_fee = -1 * tr.amount_before_fee + tr.amount_after_fee
tr.crypto_amount = -1 * tr.amount_before_fee
tr.transaction_type = 'S'
else:
tr.crypto_fee = 0
tr.crypto_amount = 0
tr.transaction_type = 'T'
tr.fiat_amount = tr.amount
tr.fiat_fee = 0
tr.save()
class Migration(migrations.Migration):
dependencies = [
('transactions', '0003_auto_20210511_0703'),
]
operations = [
migrations.RunPython(separate_fees),
]