2022-08-16 08:34:16 +00:00
|
|
|
# Generated by Django 3.2.14 on 2022-08-16 08:29
|
|
|
|
|
|
|
|
from django.db import migrations, models
|
|
|
|
|
|
|
|
|
2022-08-17 03:54:18 +00:00
|
|
|
def migrate_system_user_to_account(apps, schema_editor):
|
|
|
|
connection_token_model = apps.get_model("authentication", "ConnectionToken")
|
2022-08-16 08:34:16 +00:00
|
|
|
count = 0
|
|
|
|
bulk_size = 10000
|
|
|
|
|
|
|
|
while True:
|
|
|
|
connection_tokens = connection_token_model.objects \
|
2022-08-22 10:48:07 +00:00
|
|
|
.prefetch_related('system_user')[count:bulk_size]
|
2022-08-16 08:34:16 +00:00
|
|
|
if not connection_tokens:
|
|
|
|
break
|
|
|
|
count += len(connection_tokens)
|
|
|
|
updated = []
|
|
|
|
for connection_token in connection_tokens:
|
2023-01-17 03:48:49 +00:00
|
|
|
if not connection_token.system_user:
|
|
|
|
continue
|
2023-01-17 04:13:36 +00:00
|
|
|
connection_token.account_username = connection_token.system_user.username
|
2022-08-16 08:34:16 +00:00
|
|
|
updated.append(connection_token)
|
2023-01-17 04:13:36 +00:00
|
|
|
connection_token_model.objects.bulk_update(updated, ['account_username'])
|
2022-08-16 08:34:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('authentication', '0011_auto_20220705_1940'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='connectiontoken',
|
|
|
|
name='application',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='connectiontoken',
|
|
|
|
name='application_display',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='connectiontoken',
|
|
|
|
name='system_user_display',
|
|
|
|
),
|
|
|
|
migrations.AddField(
|
|
|
|
model_name='connectiontoken',
|
2022-10-28 07:01:17 +00:00
|
|
|
name='account_username',
|
2022-08-16 08:34:16 +00:00
|
|
|
field=models.CharField(default='', max_length=128, verbose_name='Account'),
|
|
|
|
),
|
2022-08-17 03:54:18 +00:00
|
|
|
migrations.RunPython(migrate_system_user_to_account),
|
2022-08-16 08:34:16 +00:00
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='connectiontoken',
|
|
|
|
name='system_user',
|
2022-10-26 09:56:37 +00:00
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='connectiontoken',
|
|
|
|
name='type',
|
|
|
|
),
|
2022-08-16 08:34:16 +00:00
|
|
|
]
|