Skip to content

Commit

Permalink
series: Remove the version and n_patches fields from series
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
51 changes: 51 additions & 0 deletions patchwork/migrations/0015_remove_version_n_patches.py
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',
),
]
5 changes: 0 additions & 5 deletions patchwork/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,6 @@ class Series(models.Model):
blank=True)
submitted = models.DateTimeField(default=datetime.datetime.now)
last_updated = models.DateTimeField(auto_now=True)
# Caches the latest version so we can display it without looking at the max
# of all SeriesRevision.version
version = models.IntegerField(default=1)
# This is the number of patches of the latest version.
n_patches = models.IntegerField(default=0)
# direct access to the latest revision so we can get the latest revision
# information with a JOIN
last_revision = models.OneToOneField('SeriesRevision', null=True,
Expand Down

0 comments on commit 16125d9

Please sign in to comment.