forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5444 from nyaruka/note_vs_body_pt3
Add data migration to copy body to ticket on open ticket event
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 5.0.8 on 2024-08-08 14:58 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def move_body_to_open_note(apps, schema_editor): | ||
Ticket = apps.get_model("tickets", "Ticket") | ||
|
||
num_updated = 0 | ||
|
||
for ticket in Ticket.objects.exclude(body=None).exclude(body=""): | ||
ticket.events.filter(event_type="O").update(note=ticket.body) | ||
|
||
num_updated += 1 | ||
|
||
if num_updated % 1000 == 0: # pragma: no cover | ||
print(f" > updated {num_updated} tickets") | ||
|
||
if num_updated: | ||
print(f" > Updated {num_updated} tickets") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("tickets", "0061_alter_ticket_body_alter_ticketevent_note")] | ||
|
||
operations = [migrations.RunPython(move_body_to_open_note, migrations.RunPython.noop)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters