Connecting to multiple db masters
I've encountered the multiple database issue but with a twist. I want
to propagate data across a dual master Oracle database setup which
seems to be a little different topic than the online discussions I've
seen. In order to do this I want to pass the url for both domains to
Oracle as the connection string. I've written code to make this work
but thought I'd get some input from this group as to whether this has
been done before and if not if my solution is the best approach.
I updated my local settings.py to contain a DATABASE_URL variable
which has the username, password and dsn of both domains.
DATABASE_URL = username/password@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=host1)(PORT=1234)))(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=host2)(PORT=1234)))(LOAD_BALANCE=yes)(CONNECT_DATA=
(SERVER=DEDICATED)(SID=test)))'
I added a method to the django\db\backends\oracle\base.py
DatabaseWrapper class.
def _connect_url(self):
settings_module = os.environ["DJANGO_SETTINGS_MODULE"]
mod = importlib.import_module(settings_module)
return mod.DATABASE_URL
And updated the existing _cursor method to call the new _connect_url
method.
conn_string = convert_unicode(self._connect_string())
if conn_string == '/@': # This means no connection string
information was found.
conn_url = convert_unicode(self._connect_url())
self.connection = Database.connect(conn_url,
**self.settings_dict['DATABASE_OPTIONS'])
else:
self.connection = Database.connect(conn_string,
**self.settings_dict['DATABASE_OPTIONS'])
This enables user to either use the existing functionality by
populating the existing 'DATABASE' variables, or they can comment out
the DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST,
and DATABASE_PORT in their settings.py and use the DATABASE_URL
instead. Does this look like a feasible solution?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home