From b8976f60fd306483071a7f3c50df6226936ba2ee Mon Sep 17 00:00:00 2001 From: Evangelos Foutras Date: Mon, 1 Feb 2010 05:52:57 +0200 Subject: Make the maintainer migration less stupid Why issue lots of UPDATE queries when you can only issue one? My fail. Signed-off-by: Evangelos Foutras Signed-off-by: Dan McGee --- main/migrations/0003_migrate_maintainer.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/main/migrations/0003_migrate_maintainer.py b/main/migrations/0003_migrate_maintainer.py index ec70b895..8d759271 100644 --- a/main/migrations/0003_migrate_maintainer.py +++ b/main/migrations/0003_migrate_maintainer.py @@ -8,17 +8,13 @@ class Migration: no_dry_run = True def forwards(self, orm): - for pkg in Package.objects.all(): - if pkg.maintainer_id == 0: - pkg.maintainer = None - pkg.save() + Package.objects.filter(maintainer=0).update(maintainer=None) def backwards(self, orm): - for pkg in Package.objects.all(): - if not pkg.maintainer: - pkg.maintainer_id = 0 - pkg.save() + # This will fail if foreign keys are in effect. Let's hope we'll + # never have to go backwards. :P + Package.objects.filter(maintainer=None).update(maintainer=0) models = { -- cgit v1.2.3-55-g3dc8