-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
series: Remove the version and n_patches fields from series
Now that we have migrated this information from Series to SeriesRevision, it's time to remove the fields on Series. We still provide a revision migration step we can backward if something goes wrong. Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
- Loading branch information
Damien Lespiau
committed
Jan 25, 2016
1 parent
d97ca94
commit 16125d9
Showing
2 changed files
with
51 additions
and
5 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,51 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def noop(apps, schema_editor): | ||
pass | ||
|
||
|
||
def update_version_n_patches(apps, schema_editor): | ||
Series = apps.get_model("patchwork", "Series") | ||
SeriesRevision = apps.get_model("patchwork", "SeriesRevision") | ||
|
||
query = Series.objects.all() | ||
for _, series in enumerate(query.iterator()): | ||
revisions = SeriesRevision.objects.filter(series=series). \ | ||
order_by('version').reverse() | ||
last_revision = revisions[0] | ||
|
||
for field in series._meta.local_fields: | ||
if field.name == "last_updated": | ||
field.auto_now = False | ||
|
||
series.version = last_revision.version | ||
series.n_patches = last_revision.n_patches | ||
series.save() | ||
|
||
for field in series._meta.local_fields: | ||
if field.name == "last_updated": | ||
field.auto_now = True | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('patchwork', '0014_last_revision'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(noop, update_version_n_patches), | ||
|
||
migrations.RemoveField( | ||
model_name='series', | ||
name='n_patches', | ||
), | ||
migrations.RemoveField( | ||
model_name='series', | ||
name='version', | ||
), | ||
] |
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