diff --git a/djangocms_version_locking/migrations/0002_migrate_locked_by.py b/djangocms_version_locking/migrations/0002_migrate_locked_by.py new file mode 100644 index 0000000..7c6c42f --- /dev/null +++ b/djangocms_version_locking/migrations/0002_migrate_locked_by.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.8 on 2024-11-07 07:21 + +from django.db import migrations + + +def forwards(apps, schema_editor): + db_alias = schema_editor.connection.alias + Version = apps.get_model("djangocms_versioning", "Version") + VersionLock = apps.get_model("djangocms_version_locking", "VersionLock") + + version_qs = Version.objects.using(db_alias).all() + version_lock_qs = VersionLock.objects.using(db_alias).all() + for lock_item in version_lock_qs: + locked_version = version_qs.filter(pk=lock_item.version.pk) + if locked_version: + locked_version.locked_by = lock_item.created_by + locked_version.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangocms_version_locking', '0001_initial'), + ('djangocms_versioning', '0017_merge_20230514_1027'), + ] + + operations = [ + migrations.RunPython(forwards, reverse_code=migrations.RunPython.noop) + ]