From c45768eb4a9b778bd60b8431bd56c64f19f5cd4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=82=85=E7=9D=BF=E6=9B=BC?= Date: Thu, 7 Nov 2024 16:11:42 +0800 Subject: [PATCH] add locked_by data migration file. --- .../migrations/0002_migrate_locked_by.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 djangocms_version_locking/migrations/0002_migrate_locked_by.py 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) + ]