Changeset View
Changeset View
Standalone View
Standalone View
looper/migrations/0043_c2u_datamigration.py
| # Generated by Django 2.1.2 on 2018-10-15 10:45 | # Generated by Django 2.1.2 on 2018-10-15 10:45 | ||||
| from typing import Any | |||||
| from django.conf import settings | from django.conf import settings | ||||
| from django.db import migrations, models | from django.db import migrations, models | ||||
| import django.db.models.deletion | import django.db.models.deletion | ||||
| from django.db.transaction import atomic | from django.db.transaction import atomic | ||||
| @atomic | @atomic | ||||
| def customer_to_user_id(apps, schema_editor): | def customer_to_user_id(apps: Any, schema_editor: Any) -> Any: | ||||
| Subscription = apps.get_model('looper', 'Subscription') | Subscription = apps.get_model('looper', 'Subscription') | ||||
| Order = apps.get_model('looper', 'Order') | Order = apps.get_model('looper', 'Order') | ||||
| Transaction = apps.get_model('looper', 'Transaction') | Transaction = apps.get_model('looper', 'Transaction') | ||||
| GatewayCustomerId = apps.get_model('looper', 'GatewayCustomerId') | GatewayCustomerId = apps.get_model('looper', 'GatewayCustomerId') | ||||
| PaymentMethod = apps.get_model('looper', 'PaymentMethod') | PaymentMethod = apps.get_model('looper', 'PaymentMethod') | ||||
| Address = apps.get_model('looper', 'Address') | Address = apps.get_model('looper', 'Address') | ||||
| def do(modelclass): | def do(modelclass: Any) -> Any: | ||||
| for instance in modelclass.objects.all(): | for instance in modelclass.objects.all(): | ||||
| instance.user_id = instance.customer.user.pk | instance.user_id = instance.customer.user.pk | ||||
| instance.save(update_fields={'user_id'}) | instance.save(update_fields={'user_id'}) | ||||
| do(Order) | do(Order) | ||||
| do(Subscription) | do(Subscription) | ||||
| do(Transaction) | do(Transaction) | ||||
| do(GatewayCustomerId) | do(GatewayCustomerId) | ||||
| do(PaymentMethod) | do(PaymentMethod) | ||||
| do(Address) | do(Address) | ||||
| @atomic | @atomic | ||||
| def user_id_to_customer(apps, schema_editor): | def user_id_to_customer(apps: Any, schema_editor: Any) -> Any: | ||||
| Subscription = apps.get_model('looper', 'Subscription') | Subscription = apps.get_model('looper', 'Subscription') | ||||
| Order = apps.get_model('looper', 'Order') | Order = apps.get_model('looper', 'Order') | ||||
| Transaction = apps.get_model('looper', 'Transaction') | Transaction = apps.get_model('looper', 'Transaction') | ||||
| GatewayCustomerId = apps.get_model('looper', 'GatewayCustomerId') | GatewayCustomerId = apps.get_model('looper', 'GatewayCustomerId') | ||||
| PaymentMethod = apps.get_model('looper', 'PaymentMethod') | PaymentMethod = apps.get_model('looper', 'PaymentMethod') | ||||
| Address = apps.get_model('looper', 'Address') | Address = apps.get_model('looper', 'Address') | ||||
| def do(modelclass): | def do(modelclass: Any) -> Any: | ||||
| for instance in modelclass.objects.all(): | for instance in modelclass.objects.all(): | ||||
| instance.customer_id = instance.user.customer.pk | instance.customer_id = instance.user.customer.pk | ||||
| instance.save(update_fields={'customer_id'}) | instance.save(update_fields={'customer_id'}) | ||||
| do(Order) | do(Order) | ||||
| do(Subscription) | do(Subscription) | ||||
| do(Transaction) | do(Transaction) | ||||
| do(GatewayCustomerId) | do(GatewayCustomerId) | ||||
| Show All 13 Lines | |||||