Remove outdated migration for status choices and implement normalization for task and content statuses in new migration.
This commit is contained in:
@@ -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,
|
||||
),
|
||||
]
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user