GooDrive/backend/drive/migrations/0014_private_quota_within_assigned.py
Louis Mazin ac4c0f4d6a test
2026-10-14 02:29:33 +02:00

22 lines
997 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Count private files in their owner's assigned quota, without reservation.
Only the SQL parent changes. Files remain under storage/privates/ (or at their
legacy path until move_private_storage is run). 50 Go is a cap, not a reserve.
"""
from django.db import migrations
def attach_privates(apps, schema_editor):
Space = apps.get_model('drive', 'DriveSpace')
quota = 50 * 1024 ** 3
for private in Space.objects.filter(private_owner__isnull=False).iterator():
assigned = Space.objects.filter(user_id=private.private_owner_id, private_owner__isnull=True).first()
if not assigned:
raise RuntimeError(f'Le compte {private.private_owner_id} ne possède pas d’espace attribué.')
Space.objects.filter(pk=private.pk).update(parent_id=assigned.pk, quota_bytes=quota)
class Migration(migrations.Migration):
dependencies = [('drive', '0013_private_space_quota')]
operations = [migrations.RunPython(attach_privates, migrations.RunPython.noop)]