From patchwork Tue Aug 18 17:30:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Lespiau X-Patchwork-Id: 508409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4772F1402B5 for ; Wed, 19 Aug 2015 03:30:45 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 26D6E1A0502 for ; Wed, 19 Aug 2015 03:30:45 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lists.ozlabs.org (Postfix) with ESMTP id 906101A0035 for ; Wed, 19 Aug 2015 03:30:27 +1000 (AEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 18 Aug 2015 10:30:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,703,1432623600"; d="scan'208";a="786479398" Received: from spmulapu-mobl.amr.corp.intel.com (HELO strange.amr.corp.intel.com) ([10.254.106.50]) by orsmga002.jf.intel.com with ESMTP; 18 Aug 2015 10:30:22 -0700 From: Damien Lespiau To: patchwork@lists.ozlabs.org Subject: [PATCH 1/3] migrations: Use a data migration to load initial states and tags Date: Tue, 18 Aug 2015 18:30:18 +0100 Message-Id: <1439919020-13293-2-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1439919020-13293-1-git-send-email-damien.lespiau@intel.com> References: <1439919020-13293-1-git-send-email-damien.lespiau@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" django 1.9 is going to remove initial data through fixtures: If an application uses migrations, there is no automatic loading of fixtures. Since migrations will be required for applications in Django 1.9, this behavior is considered deprecated. If you want to load initial data for an app, consider doing it in a data migration. Source: https://docs.djangoproject.com/en/1.8/howto/initial-data/ So, for convenience (to not have to load fixtures by hand), load the content of the state and tag tables as a migration step. We can then remove a step in the install process: the initial data will populated by the migration system (syncdb is running that under the hood). Signed-off-by: Damien Lespiau --- docs/INSTALL | 5 ---- patchwork/migrations/0002_load_initial_data.py | 37 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 patchwork/migrations/0002_load_initial_data.py diff --git a/docs/INSTALL b/docs/INSTALL index bd95770..1a5d777 100644 --- a/docs/INSTALL +++ b/docs/INSTALL @@ -148,11 +148,6 @@ in brackets): PYTHONPATH=lib/python ./manage.py collectstatic - You'll also need to load the initial tags and states into the - patchwork database: - - PYTHONPATH=lib/python ./manage.py loaddata default_tags default_states - Finally, add privileges for your mail and web users. This is only needed if you use the ident-based approach. If you use password-based database authentication, you can skip this step. diff --git a/patchwork/migrations/0002_load_initial_data.py b/patchwork/migrations/0002_load_initial_data.py new file mode 100644 index 0000000..118bee1 --- /dev/null +++ b/patchwork/migrations/0002_load_initial_data.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.core.management import call_command + + +# https://docs.djangoproject.com/en/1.8/topics/migrations/#data-migrations + +def load_fixture(name): + call_command('loaddata', name, app_label='patchwork', verbosity=0, + interactive=False) + +def load_states(apps, schema_editor): + load_fixture('default_states') + +def load_tags(apps, schema_editor): + load_fixture('default_tags') + +def reset_states(apps, schema_editor): + State = apps.get_model('patchwork', 'State') + State.objects.all().delete() + +def reset_tags(apps, schema_editor): + Tag = apps.get_model('patchwork', 'Tag') + Tag.objects.all().delete() + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0001_initial'), + ] + + operations = [ + migrations.RunPython(load_states, reset_states), + migrations.RunPython(load_tags, reset_tags), + ]