2020-10-17 14:33:23 +00:00
|
|
|
# Generated by Django 3.1.2 on 2020-10-17 14:26
|
|
|
|
|
|
|
|
from django.apps.registry import Apps
|
|
|
|
from django.db import migrations
|
|
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
|
|
|
|
|
|
|
|
|
|
|
def fix_missing_token_identifier(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
2020-11-04 09:41:18 +00:00
|
|
|
User = apps.get_model("passbook_core", "User")
|
|
|
|
Token = apps.get_model("passbook_core", "Token")
|
2020-10-17 15:06:08 +00:00
|
|
|
from passbook.outposts.models import Outpost
|
|
|
|
|
2020-11-04 09:54:44 +00:00
|
|
|
for outpost in (
|
|
|
|
Outpost.objects.using(schema_editor.connection.alias).all().only("pk")
|
|
|
|
):
|
2020-11-04 09:41:18 +00:00
|
|
|
user_identifier = outpost.user_identifier
|
|
|
|
user = User.objects.get(username=user_identifier)
|
|
|
|
tokens = Token.objects.filter(user=user)
|
|
|
|
for token in tokens:
|
|
|
|
if token.identifier != outpost.token_identifier:
|
|
|
|
token.identifier = outpost.token_identifier
|
|
|
|
token.save()
|
2020-10-17 14:33:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2020-10-18 12:34:22 +00:00
|
|
|
("passbook_core", "0014_auto_20201018_1158"),
|
2020-10-17 14:33:23 +00:00
|
|
|
("passbook_outposts", "0008_auto_20201014_1547"),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RunPython(fix_missing_token_identifier),
|
|
|
|
]
|