Skip to content

Commit

Permalink
add locked_by data migration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
FreemanPancake committed Nov 7, 2024
1 parent 80e68fe commit c45768e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions djangocms_version_locking/migrations/0002_migrate_locked_by.py
Original file line number Diff line number Diff line change
@@ -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)
]

0 comments on commit c45768e

Please sign in to comment.