This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Easily use fixtures in Django 1.7+ data migrations.

The app also contains a management command to automatically convert initial_data.* into migrations.

Prior to Django 1.7 initial_data.* files where automatically run when the management command sync_db was run, however this behaviour was discontinued in Django 1.7. Thus, this app is useful if you rely on this behaviour.

Essentially it leaves the initial_data.* file in place and generates a data migration - as outlined in the docs.

Install

pip install django-migration-fixture

Then add django_migration_fixture to your INSTALLED_APPS.

INSTALLED_APPS += (
        'django_migration_fixture',
)

Usage

To automatically change your old-skool initial_data.* files the simplest method is to simply call the create_initial_data_fixtures management command.

./manage.py create_initial_data_fixtures

The management command will automatically look for initial_data.* files in your list of INSTALLED_APPS and for each file found creates a data migration, similar to the following;

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django_migration_fixture import fixture
import myapp

class Migration(migrations.Migration):

        operations = [
                migrations.RunPython(**fixture(myapp, 'initial_data.yaml'))
        ]

From this point it’s just a matter of running migrate to apply your data migrations.

Note that this solution also supports rolling back your migration by deleting using primary key. If your migration should not be reversible then you can pass reversible=False to fixture().

You can use this app for any fixtures, they don’t have to be your initial_data files. Simply create a empty migration and add a call to migrations.RunPython(**fixture(myapp, 'foo.yaml')).

API Documentation

fixture(app, fixtures, fixtures_dir='fixtures', raise_does_not_exist=False, reversible=True)

  • app is a Django app that contains your fixtures
  • fixtures can take either a string or a list of fixture files. The extension is used as the format supplied to django.core.serializers.deserialize
  • fixtures_dir is the directory inside your app that contains the fixtures
  • ignore_does_not_exist - if set to True then django_migration_fixture.FixtureObjectDoesNotExist is raised if when attempting a rollback the object in the fixture does not exist.
  • reversible - if set to False then any attempt to reverse the migration will raise django.db.migrations.migration.IrreversibleError.

Essentially fixture() returns a dict containing the keys code and reverse_code which attempt to apply your fixture and rollback your fixture, respectively.

Inspiration

While attempting to migrate a large Django project to 1.7 I came across an issue which caused me to create Django ticket 24023.

The project has a lot of fixtures that ensure a baseline state and converting them to code isn’t really ideal, thus this project.

That issue has since been closed as a duplicate of ticket 23699 which itself has been closed and released in Django 1.7.2.

Needless to say, you may still need to create data migrations for fixtures regardless of the issue I came across.

Author

Alex Hayes <alex@alution.com>

Release History

Release History

0.5.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-migration-fixture-0.5.1.tar.gz (7.6 kB) Copy SHA256 Checksum SHA256 Source Jul 24, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting