etesync-server/django_etesync/migrations/0029_auto_20200312_1849.py

36 lines
1.0 KiB
Python
Raw Normal View History

2020-03-12 19:02:27 +00:00
# Generated by Django 3.0.3 on 2020-03-12 18:49
from django.db import migrations
2020-04-16 09:56:42 +00:00
from django.utils.crypto import get_random_string
def generate_rev_uid(length=32):
return get_random_string(length)
2020-03-12 19:02:27 +00:00
def add_collection_main_item(apps, schema_editor):
Collection = apps.get_model('django_etesync', 'Collection')
CollectionItem = apps.get_model('django_etesync', 'CollectionItem')
CollectionItemRevision = apps.get_model('django_etesync', 'CollectionItemRevision')
for col in Collection.objects.all():
main_item = CollectionItem.objects.create(uid=None, encryptionKey=None, version=col.version, collection=col)
col.mainItem = main_item
col.save()
CollectionItemRevision.objects.create(
uid=generate_rev_uid(),
hmac='hmac-hash',
item=main_item)
class Migration(migrations.Migration):
dependencies = [
('django_etesync', '0028_auto_20200312_1819'),
]
operations = [
migrations.RunPython(add_collection_main_item),
]