Skip to content

Instantly share code, notes, and snippets.

@vshjxyz
Last active December 13, 2015 23:58
Show Gist options
  • Save vshjxyz/4995164 to your computer and use it in GitHub Desktop.
Save vshjxyz/4995164 to your computer and use it in GitHub Desktop.
This is the content of my __init__.py to perform migrations on appfog I needed this because the django-allauth package need to do some migrations initially to work. The Appfog's lack of post-deploy scripts forced me to create a script that I had to put inside one of the apps in my project django_project/appname/management/__init__.py should make…
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.db.models.signals import post_syncdb
from south.models import MigrationHistory
import pizzanuvola_teaser.settings as settings
def migration_exists(appname, migrationnumber):
appname = appname.split('.')[-1]
return MigrationHistory.objects.filter(app_name=appname, migration__icontains=migrationnumber).exists()
def load_data(app, sender, **kwargs):
if app.__name__ == settings.INSTALLED_APPS[-1] + ".models":
migrations = {
'allauth.socialaccount': [
'0001',
'0002',
'0003',
'0004',
'0005',
'0006',
'0007',
'0008',
],
'allauth.socialaccount.providers.facebook': [
'0001',
'0002',
],
}
for appname, migrationlist in migrations.iteritems():
for migration in migrationlist:
if not migration_exists(appname, migration):
try:
call_command('migrate', appname, migration)
except ImproperlyConfigured:
pass
post_syncdb.connect(load_data)
@jeyoor
Copy link

jeyoor commented Mar 2, 2013

Amazing help, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment