-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#109] Turn approval status column from to be nteger enumeration to s…
…tring enumeration
- Loading branch information
Showing
3 changed files
with
92 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.24 on 2019-10-20 15:27 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
from django.db.models import Case, When, Value | ||
|
||
|
||
def migrate_status(apps, schema_editor): | ||
from river.models import PENDING, APPROVED | ||
TransitionApproval = apps.get_model('river', 'TransitionApproval') | ||
TransitionApproval.objects.update(status2=Case( | ||
When(status=0, then=Value(PENDING)), | ||
When(status=1, then=Value(APPROVED)) | ||
)) | ||
|
||
|
||
def reverse_migrate_status(apps, schema_editor): | ||
from river.models import PENDING, APPROVED | ||
TransitionApproval = apps.get_model('river', 'TransitionApproval') | ||
TransitionApproval.objects.update(status=Case( | ||
When(status2=PENDING, then=Value(0)), | ||
When(status2=APPROVED, then=Value(1)), | ||
)) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('river', '0004_auto_20191016_1731'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='transitionapproval', | ||
name='status2', | ||
field=models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved')], default='pending', max_length=100, verbose_name='Status'), | ||
), | ||
migrations.RunPython(migrate_status, reverse_code=reverse_migrate_status), | ||
migrations.RemoveField( | ||
model_name='transitionapproval', | ||
name='status', | ||
), | ||
migrations.RenameField('transitionapproval', 'status2', 'status'), | ||
] |
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