-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add migration to remove all Observation* events that are differ…
…ent only in newline style
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
tasks/apps/tree/migrations/0041_remove_unchanged_observation_events.py
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,31 @@ | ||
# Generated by Django 4.2.16 on 2024-10-12 14:32 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def forward_func(apps, schema_editor): | ||
ObservationRecontextualized = apps.get_model('tree', 'ObservationRecontextualized') | ||
ObservationReinterpreted = apps.get_model('tree', 'ObservationReinterpreted') | ||
ObservationReflectedUpon = apps.get_model('tree', 'ObservationReflectedUpon') | ||
|
||
db_alias = schema_editor.connection.alias | ||
|
||
model_mapping = { | ||
ObservationRecontextualized: 'situation', | ||
ObservationReinterpreted: 'interpretation', | ||
ObservationReflectedUpon: 'approach' | ||
} | ||
|
||
for model, field in model_mapping.items(): | ||
for instance in model.objects.using(db_alias).all(): | ||
if getattr(instance, field).strip().replace('\r', '') == getattr(instance, f'old_{field}').strip().replace('\r', ''): | ||
instance.delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("tree", "0040_remove_empty_reflections_and_plans"), | ||
] | ||
|
||
operations = [migrations.RunPython(forward_func, 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