Пример #1
0
 def handle(self, *args, **options):
     if 'test' not in sys.argv or not settings.FIXTURE_DIRS:
         print 'ERROR: not in test env'
         exit(1)
     HandleSouth.disable()
     call_command('syncdb', interactive=False)
     HandleSouth.enable()
     # migration already done
     call_command('loaddata', 'db_south', verbosity='0')
     call_command('loaddata', 'db_user', verbosity='0')
     for app in HandleSouth.get_apps():
         if not self.has_fixtures(app):
             continue
         print 'loading fixtures: %s' % app
         call_command('loaddata', 'db_%s' % app, verbosity='0')
         nb = MigrationHistory.objects.filter(app_name=app).count()
         files = os.listdir('%s/%s/migrations' % (settings.ROOT_DIR, app))
         migrations = [migration for migration in files
                       if self.regex.match(migration)]
         migrations.sort()
         for migration in migrations[nb:]:
             # XXX schemamigration will always be done by the syncdb command
             #     they shouldn't be done again: e.g raise table not found
             #     datamigration are 'manually' created unlike
             #     schemamigration so a schemamigration should always
             #     contain '_auto__' in its name
             if '_auto__' in migration:
                 call_command('migrate', app, migration, fake=True)
             else:
                 call_command('migrate', app, migration)
         self.migrate(app)
     # update the done migration
     self.migrate('south')