From d9078b2751a777f96bf727b9d3bda851690af319 Mon Sep 17 00:00:00 2001 From: Erwan Rouchet <rouchet@teklia.com> Date: Mon, 14 Dec 2020 14:13:15 +0100 Subject: [PATCH] Randomize revisions --- .../migrations/0024_migrate_datasource.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arkindex/documents/migrations/0024_migrate_datasource.py b/arkindex/documents/migrations/0024_migrate_datasource.py index b994d4b268..7ba7bd5cd8 100644 --- a/arkindex/documents/migrations/0024_migrate_datasource.py +++ b/arkindex/documents/migrations/0024_migrate_datasource.py @@ -1,6 +1,7 @@ # Generated by Django 3.1.3 on 2020-11-30 10:40 import os +import uuid from django.db import migrations, models @@ -53,19 +54,22 @@ def migrate_data_sources(apps, schema_editor): 'type': str(source.type), } ) - revision, _ = repo.revisions.get_or_create( - hash='0' * 32, - message='Migrated DataSource', - author='Arkindex', - ) - # There can be multiple DataSources with the same slug and revision, - # but with a different type, so we have to use get_or_create. - version, _ = worker.workerversion_set.get_or_create( + + # To ensure we cannot get duplicate worker version IDs when re-applying + # unique constraints later, we just keep on trying to get a new revision. + created = False + while not created: + revision, created = repo.revisions.get_or_create( + hash=uuid.uuid4().hex, + message='Migrated DataSource', + author='Arkindex', + ) + + version = worker.workerversion_set.create( revision=revision, - defaults={ - 'configuration': {} - }, + configuration={}, ) + source.elements.update(source=None, worker_version=version) source.classifications.update(source=None, worker_version=version) source.transcriptions.update(source=None, worker_version=version) -- GitLab