-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Django's own DurationField. Fixes #183
Migrations for 'testcases': - Alter field estimated_time on testcase Migrations for 'testruns': - Alter field estimated_time on testrun Will properly convert existing field values
- Loading branch information
Showing
4 changed files
with
99 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,48 @@ | ||
# Generated by Django 2.0.3 on 2018-03-13 21:35 | ||
from datetime import timedelta | ||
from django.db import migrations, models | ||
|
||
|
||
def forward(apps, schema_editor): | ||
TestCase = apps.get_model('testcases', 'TestCase') | ||
|
||
for tc in TestCase.objects.all(): | ||
tc.estimated_time_new = timedelta(seconds=tc.estimated_time) | ||
tc.save() | ||
|
||
|
||
def reverse(apps, schema_editor): | ||
TestCase = apps.get_model('testcases', 'TestCase') | ||
|
||
for tc in TestCase.objects.all(): | ||
tc.estimated_time = tc.estimated_time_new.total_seconds() | ||
tc.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('testcases', '0015_rename_testcasebug'), | ||
] | ||
|
||
operations = [ | ||
# add a timedelta field | ||
migrations.AddField( | ||
model_name='testcase', | ||
name='estimated_time_new', | ||
field=models.DurationField(default=timedelta(0)), | ||
), | ||
# migrate the values | ||
migrations.RunPython(forward, reverse), | ||
# remove the integer field | ||
migrations.RemoveField( | ||
model_name='testcase', | ||
name='estimated_time', | ||
), | ||
# rename the new field to the old name | ||
migrations.RenameField( | ||
model_name='testcase', | ||
old_name='estimated_time_new', | ||
new_name='estimated_time', | ||
), | ||
] |
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,48 @@ | ||
# Generated by Django 2.0.3 on 2018-03-13 21:35 | ||
from datetime import timedelta | ||
from django.db import migrations, models | ||
|
||
|
||
def forward(apps, schema_editor): | ||
TestRun = apps.get_model('testruns', 'TestRun') | ||
|
||
for tr in TestRun.objects.all(): | ||
tr.estimated_time_new = timedelta(seconds=tr.estimated_time) | ||
tr.save() | ||
|
||
|
||
def reverse(apps, schema_editor): | ||
TestRun = apps.get_model('testruns', 'TestRun') | ||
|
||
for tr in TestRun.objects.all(): | ||
tr.estimated_time = tr.estimated_time_new.total_seconds() | ||
tr.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('testruns', '0009_rename_testtag'), | ||
] | ||
|
||
operations = [ | ||
# add a timedelta field | ||
migrations.AddField( | ||
model_name='testrun', | ||
name='estimated_time_new', | ||
field=models.DurationField(default=timedelta(0)), | ||
), | ||
# migrate the values | ||
migrations.RunPython(forward, reverse), | ||
# remove the integer field | ||
migrations.RemoveField( | ||
model_name='testrun', | ||
name='estimated_time', | ||
), | ||
# rename the new field to the old name | ||
migrations.RenameField( | ||
model_name='testrun', | ||
old_name='estimated_time_new', | ||
new_name='estimated_time', | ||
), | ||
] |
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