From 0924a8436cf7b6dc3ef31c943063100d9cbbb2ac Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Tue, 11 Nov 2025 14:43:02 +0000 Subject: [PATCH] Remove outdated migration for status choices and implement normalization for task and content statuses in new migration. --- .../migrations/0002_update_status_choices.py | 45 ---------------- .../migrations/0006_update_status_choices.py | 54 ++++++++++++++++--- 2 files changed, 48 insertions(+), 51 deletions(-) delete mode 100644 backend/igny8_core/modules/writer/migrations/0002_update_status_choices.py diff --git a/backend/igny8_core/modules/writer/migrations/0002_update_status_choices.py b/backend/igny8_core/modules/writer/migrations/0002_update_status_choices.py deleted file mode 100644 index 858ce34f..00000000 --- a/backend/igny8_core/modules/writer/migrations/0002_update_status_choices.py +++ /dev/null @@ -1,45 +0,0 @@ -from django.db import migrations, models - - -def migrate_content_status_forward(apps, schema_editor): - Content = apps.get_model('writer', 'Content') - Content.objects.filter(status='published').update(status='publish') - - -def migrate_content_status_backward(apps, schema_editor): - Content = apps.get_model('writer', 'Content') - Content.objects.filter(status='publish').update(status='published') - - -class Migration(migrations.Migration): - - dependencies = [ - ('writer', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='tasks', - name='status', - field=models.CharField( - choices=[('queued', 'Queued'), ('completed', 'Completed')], - default='queued', - max_length=50, - ), - ), - migrations.AlterField( - model_name='content', - name='status', - field=models.CharField( - choices=[('draft', 'Draft'), ('review', 'Review'), ('publish', 'Publish')], - default='draft', - help_text='Content workflow status (draft, review, publish)', - max_length=50, - ), - ), - migrations.RunPython( - migrate_content_status_forward, - migrate_content_status_backward, - ), - ] - diff --git a/backend/igny8_core/modules/writer/migrations/0006_update_status_choices.py b/backend/igny8_core/modules/writer/migrations/0006_update_status_choices.py index e0daef95..86fde28a 100644 --- a/backend/igny8_core/modules/writer/migrations/0006_update_status_choices.py +++ b/backend/igny8_core/modules/writer/migrations/0006_update_status_choices.py @@ -1,6 +1,32 @@ -# Generated manually to update status field choices +# Generated manually to update status field choices and normalize data -from django.db import migrations +from django.db import migrations, models + + +def normalize_statuses_forward(apps, schema_editor): + Tasks = apps.get_model('writer', 'Tasks') + Content = apps.get_model('writer', 'Content') + + # Normalize task statuses to queued/completed + queued_states = {'queued', 'in_progress'} + completed_states = {'draft', 'review', 'published', 'completed'} + + Tasks.objects.filter(status__in=queued_states).update(status='queued') + Tasks.objects.filter(status__in=completed_states).update(status='completed') + + # Normalize content statuses: published -> publish (new choice) + Content.objects.filter(status='published').update(status='publish') + + +def normalize_statuses_backward(apps, schema_editor): + Tasks = apps.get_model('writer', 'Tasks') + Content = apps.get_model('writer', 'Content') + + # Restore pre-normalization values + Tasks.objects.filter(status='queued').update(status='queued') + Tasks.objects.filter(status='completed').update(status='published') + + Content.objects.filter(status='publish').update(status='published') class Migration(migrations.Migration): @@ -10,9 +36,25 @@ class Migration(migrations.Migration): ] operations = [ - # No database changes needed - just updating Python-level choices - # Tasks status: queued, completed - # Content status: draft, review, published - # Existing data will remain valid + migrations.RunPython(normalize_statuses_forward, normalize_statuses_backward), + migrations.AlterField( + model_name='tasks', + name='status', + field=models.CharField( + choices=[('queued', 'Queued'), ('completed', 'Completed')], + default='queued', + max_length=50, + ), + ), + migrations.AlterField( + model_name='content', + name='status', + field=models.CharField( + choices=[('draft', 'Draft'), ('review', 'Review'), ('publish', 'Publish')], + default='draft', + help_text='Content workflow status (draft, review, publish)', + max_length=50, + ), + ), ]