mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 10:49:15 +02:00
Moved actor domain to a dedicated table
This commit is contained in:
parent
060543f62c
commit
7ac3bb98da
14 changed files with 244 additions and 44 deletions
|
@ -0,0 +1,56 @@
|
|||
# Generated by Django 2.0.9 on 2018-11-14 08:55
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
def populate_domains(apps, schema_editor):
|
||||
Domain = apps.get_model("federation", "Domain")
|
||||
Actor = apps.get_model("federation", "Actor")
|
||||
|
||||
domains = set(
|
||||
[v.lower() for v in Actor.objects.values_list("old_domain", flat=True)]
|
||||
)
|
||||
for domain in sorted(domains):
|
||||
print("Populating domain {}...".format(domain))
|
||||
first_actor = (
|
||||
Actor.objects.order_by("creation_date")
|
||||
.exclude(creation_date=None)
|
||||
.filter(old_domain__iexact=domain)
|
||||
.first()
|
||||
)
|
||||
|
||||
if first_actor:
|
||||
first_seen = first_actor.creation_date
|
||||
else:
|
||||
first_seen = django.utils.timezone.now()
|
||||
|
||||
Domain.objects.update_or_create(
|
||||
name=domain, defaults={"creation_date": first_seen}
|
||||
)
|
||||
|
||||
for domain in Domain.objects.all():
|
||||
Actor.objects.filter(old_domain__iexact=domain.name).update(domain=domain)
|
||||
|
||||
|
||||
def skip(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("federation", "0014_auto_20181205_0958")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(populate_domains, skip),
|
||||
migrations.AlterField(
|
||||
model_name="actor",
|
||||
name="domain",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="actors",
|
||||
to="federation.Domain",
|
||||
),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue