Ticket #14108: multi_db_loaddata.diff

File multi_db_loaddata.diff, 2.3 KB (added by berto, 14 years ago)

load data into multiple distinct databases

  • django/core/management/commands/loaddata.py

    diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
    index 8bf89c9..31a011a 100644
    a b class Command(BaseCommand):  
    9191                app_module_paths.append(app.__file__)
    9292
    9393        app_fixtures = [os.path.join(os.path.dirname(path), 'fixtures') for path in app_module_paths]
     94        multi_db = options.get('multi_db', False)
    9495        for fixture_label in fixture_labels:
    9596            parts = fixture_label.split('.')
    9697
    class Command(BaseCommand):  
    189190                            # If the fixture we loaded contains 0 objects, assume that an
    190191                            # error was encountered during fixture loading.
    191192                            if objects_in_fixture == 0:
     193                                if multi_db:
     194                                    continue
     195
    192196                                sys.stderr.write(
    193197                                    self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)\n" %
    194198                                        (fixture_name)))
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    index 10bd6c6..0e6613b 100644
    a b class TestCase(TransactionTestCase):  
    491491
    492492        # If the test case has a multi_db=True flag, setup all databases.
    493493        # Otherwise, just use default.
    494         if getattr(self, 'multi_db', False):
     494        multi_db = getattr(self, 'multi_db', False)
     495        if multi_db:
    495496            databases = connections
    496497        else:
    497498            databases = [DEFAULT_DB_ALIAS]
    class TestCase(TransactionTestCase):  
    509510                call_command('loaddata', *self.fixtures, **{
    510511                                                            'verbosity': 0,
    511512                                                            'commit': False,
    512                                                             'database': db
     513                                                            'database': db,
     514                                                            'multi_db': multi_db,
    513515                                                            })
    514516
    515517    def _fixture_teardown(self):
Back to Top