From 1e27451f55a8ba9246b6b0c62c395f6dc6c14d89 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 4 Sep 2019 14:51:54 +0200 Subject: Use UUID for operations and datings --- ishtar_common/utils_migrations.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ishtar_common/utils_migrations.py') diff --git a/ishtar_common/utils_migrations.py b/ishtar_common/utils_migrations.py index 62b6720c6..bbe308f4e 100644 --- a/ishtar_common/utils_migrations.py +++ b/ishtar_common/utils_migrations.py @@ -5,6 +5,7 @@ import datetime import json import os import sys +import uuid from django.core.files import File from django.db import connection @@ -154,3 +155,17 @@ def m2m_historization_init(obj): u"history_m2m = '" + json.dumps(hist_values).replace(u"'", u"''") + u"'::json WHERE id = %s", [obj.pk] ) + + +def migrate_uuid(model): + for obj in model.objects.all(): + obj.uuid = uuid.uuid4() + obj.skip_history_when_saving = True + obj.save() + + +def set_uuid_helper(module, model_name): + def set_uuid(apps, schema_editor): + model = apps.get_model(module, model_name) + migrate_uuid(model) + return set_uuid -- cgit v1.2.3