Changes between Initial Version and Version 1 of PreviousMultipleDatabaseBranch

09/11/08 00:58:35 (14 years ago)

Moved the information about the now obsolete multi db branch here


  • PreviousMultipleDatabaseBranch

    v1 v1  
     1'''This page describes an out-dated Django branch from 2006 which attempted to address #1142 by adding support for multiple database connections. The branch is here: source:/django/branches/multiple-db-support . This page is preserved purely for historic interest; you should not attempt to use the branch.'''
     3== Status as of 3rd September 2006 ==
     5'''FEATURE COMPLETE''' (alpha)
     7All features are implemented and all tests pass. Much work remains in documenting the new features and extending test coverage.
     9Most of the basic implementation is done, with the exception of the items in this todo list:
     12||Fix syncdb is not implemented correctly using new features.||DONE||
     13||Merge to trunk [3661]. This trunk changeset moves a number of test features and removes the othertests directory, and will need a lot of hand-merging||DONE in [3712]||
     15||MODELS entry in OTHER_DATABASES not model._meta.db_connection||DONE||
     16||Move connection info to manager||DONE||
     17||Tests for thread/request isolation||DONE||
     18||Generate sql for dropping tables in django.db.backends.sql.ansi||DONE||
     19||Generate sql for resetting sequences in postgres backend SchemaBuilder subclass||DONE||
     20||When validating models, warn user if a model references another model that is configured to use a different connection||DONE||
     21||Create mutliple_db.txt doc documenting use of settings, transactions, etc.||||
     22||Link to multiple db doc from other docs where appropriate||||
     23||Review tests and extend where appropriate||||
     25== The plan ==
     27 * Avoid any change that impacts backward compatibility. The intent is to add new functionality for those who need it, not to change the most common use case of a single database connection.
     29 * Add a new settings variable, OTHER_DATABASES. OTHER_DATABASES is a dict of named database connection parameter sets. In each set, the keys are the same as the standard database connection settings variables. Each set of settings may also define a list of models that will use that connection by default. Each item in the MODELS list may an app label (in which case it applies to all models with that app label) or app_label.Model, in which case it applies only to that specific model.
     34    'a': { 'DATABASE_ENGINE': 'sqlite3',
     35           'DATABASE_NAME': '/tmp/dba.db'
     36           'MODELS': ['app_label', 'app_label_2.Model']
     37    },
     38    'b': { 'DATABASE_ENGINE': 'sqlite3',
     39           'DATABASE_NAME': '/tmp/dbb.db'
     40    }}
     45 * Add db attribute to Managers. This allows access to the connection that a model should use, as determined by settings. It may also be changed on the fly to use a different connection for a particular query or set of queries. When assigning to Manager.db, assign a django.db.ConnectionInfo; the easiest way to get one is from the django.db.connections dict.
     49class Artist(models.Model):
     50    name = models.CharField(maxlength=100)
     51    alive = models.BooleanField(default=True)
     53    def __str__(self):
     54        return'
     56class Widget(models.Model):
     57    code = models.CharField(maxlength=10, unique=True)
     58    weight = models.IntegerField()
     60    def __str__(self):
     61        return self.code
     63settings.OTHER_DATABASES['a']['MODELS'] = ['Artist']
     64settings.OTHER_DATABASES['b']['MODELS'] = ['Widget']
     66# get the db connection
     67connection = Artist.objects.db.connection
     69# assign another connection
     70Widget.objects.db = connections['other_widget_connection']
     74 * Allow transaction decorators, etc to take optional connections argument. Without that argument, transactions will apply across all connections already in use.
     76 * Move generation of schema manipulating sql (CREATE TABLE, etc) from into django.db.backends.ansi.sql. Schema statements are build with a SchemaBuilder instance; each backend gets an instance in its creation module as creation.builder.
     78 * Add methods to Manager to support per-model installation. This will enable each model to be installed using the connection that it specifies. It causes some complications, mainly in determining the correct order in which to install. My current solution is to depend on the developer already having figure that out by defining her models in a sensible order; and, when that fails, punting any unresolved  constraints to the end of the syncdb or install process. The manager methods will delegate to each model's backend to do the sql creation.
Back to Top