Django 1.7 - Named migration directory

109 views
Skip to first unread message

Val Neekman

unread,
Dec 23, 2013, 6:57:30 PM12/23/13
to django-d...@googlegroups.com
I am wondering if it would be a good idea for a django app to name its migration directory and if nothing is provided then the name would default to 'migrations'.

The case: (let's call it a GEO app)

GEO app looks at the setting.py file for a flag called "GEO_USING_GEO_DJANGO".

# in models.py

if settings.GEO_USING_GEO_DJANGO:
    from django.contrib.gis.db import models
    from django.contrib.gis.geos import Point
else:
    from django.db import models

class Location(models.Model):

    if settings.GEO_USING_GEO_DJANGO:
        point = models.PointField(_('Point'), default='POINT(0.0 0.0)')
    else:
        # lat/lng of location
        lat = models.FloatField(_('Latitude'), default=0.0)
        lng = models.FloatField(_('Longitude'), default=0.0)

    objects = models.GeoManager() if settings.GEO_USING_GEO_DJANGO else models.Manager()

The above may not be the best practice here, but it works really well for people who don't want to install PostGIS and all the required software. All they have to do is to set GEO_USING_GEO_DJANGO = False and use geopy for lat/lng calculation.

This is to support both geoDjango and non-geoDjango users, and from the same source code.

Now, all works great till the first migration. Then game is over and the maintainer has to either stick with the geoDjango or the non-geoDjango version as far as the migration goes.

Only if the app could set its own migration directory!

in settings.py
---------------------
If GEO_USING_GEO_DJANGO:
   GEO_MIGRATION_DIR_NAME = 'migrations_geo'

The maintainer of the app would set GEO_USING_GEO_DJANGO=True and run  schemamigration, then set GEO_USING_GEO_DJANGO=False and rerun the schemamigration again. We'd end up with two distinct migration directories.

The end users just have to set GEO_USING_GEO_DJANGO=True/False.

I know this is not an ideal solution, but if avoiding duplicate versions of the same application was the final goal, this would achieve it.

This would complicate things for sure, but is there an easier way to avoid the duplicate source code?

Thanks,

Val








Andrew Godwin

unread,
Dec 23, 2013, 7:08:48 PM12/23/13
to django-d...@googlegroups.com
There's already a setting for changing an app's migrations directory, called MIGRATION_MODULES. The app can just instruct people who want to not use PostGIS to set that to a different place if they want to ship the app like that, achieving exactly the result you want without an extra setting per app :)

Andrew


--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CADy_H8ESPLR24Y7tD6xNxSS-%2BkT%3Dwc2a-60boN%3DAZ5Aphms3KA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Val Neekman

unread,
Dec 23, 2013, 7:22:36 PM12/23/13
to django-d...@googlegroups.com
How did I miss that. Excellent!

Thanks.

Val



Reply all
Reply to author
Forward
0 new messages