22 lines
997 B
Python
22 lines
997 B
Python
"""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)]
|