diff --git a/arkindex/documents/migrations/0024_migrate_datasource.py b/arkindex/documents/migrations/0024_migrate_datasource.py index b994d4b268528d5466a7c8fab567f8793dd19afc..7ba7bd5cd8e6d46a5ffa90917d3b8b4b36369cc0 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)