root / env / lib / python2.7 / site-packages / south / db / __init__.py @ d1a4905f
History | View | Annotate | Download (3.34 KB)
1 |
|
---|---|
2 |
# Establish the common DatabaseOperations instance, which we call 'db'.
|
3 |
# Much thanks to cmkmrr for a lot of the code base here
|
4 |
|
5 |
from django.conf import settings |
6 |
import sys |
7 |
|
8 |
# A few aliases, because there's FQMNs now
|
9 |
engine_modules = { |
10 |
'django.db.backends.postgresql_psycopg2': 'postgresql_psycopg2', |
11 |
'django.db.backends.sqlite3': 'sqlite3', |
12 |
'django.db.backends.mysql': 'mysql', |
13 |
'django.db.backends.oracle': 'oracle', |
14 |
'sql_server.pyodbc': 'sql_server.pyodbc', #django-pyodbc |
15 |
'sqlserver_ado': 'sql_server.pyodbc', #django-mssql |
16 |
'firebird': 'firebird', #django-firebird |
17 |
'django.contrib.gis.db.backends.postgis': 'postgresql_psycopg2', |
18 |
'django.contrib.gis.db.backends.spatialite': 'sqlite3', |
19 |
'django.contrib.gis.db.backends.mysql': 'mysql', |
20 |
'django.contrib.gis.db.backends.oracle': 'oracle', |
21 |
'doj.backends.zxjdbc.postgresql': 'postgresql_psycopg2', #django-jython |
22 |
'doj.backends.zxjdbc.mysql': 'mysql', #django-jython |
23 |
'doj.backends.zxjdbc.oracle': 'oracle', #django-jython |
24 |
} |
25 |
|
26 |
# First, work out if we're multi-db or not, and which databases we have
|
27 |
try:
|
28 |
from django.db import DEFAULT_DB_ALIAS |
29 |
except ImportError: |
30 |
#### 1.1 or below ####
|
31 |
# We'll 'fake' multi-db; set the default alias
|
32 |
DEFAULT_DB_ALIAS = 'default'
|
33 |
# SOUTH_DATABASE_ADAPTER is an optional override if you have a different module
|
34 |
engine = getattr(settings, "SOUTH_DATABASE_ADAPTER", "south.db.%s" % settings.DATABASE_ENGINE) |
35 |
# And then, we have one database with one engine
|
36 |
db_engines = {DEFAULT_DB_ALIAS: engine} |
37 |
else:
|
38 |
#### 1.2 or above ####
|
39 |
# Loop over the defined databases, gathering up their engines
|
40 |
db_engines = dict([
|
41 |
# Note we check to see if contrib.gis has overridden us.
|
42 |
(alias, "south.db.%s" % engine_modules[db_settings['ENGINE']]) |
43 |
for alias, db_settings in settings.DATABASES.items() |
44 |
if db_settings['ENGINE'] in engine_modules |
45 |
]) |
46 |
# Update with any overrides
|
47 |
db_engines.update(getattr(settings, "SOUTH_DATABASE_ADAPTERS", {})) |
48 |
# Check there's no None engines, or...
|
49 |
for alias, engine in db_engines.items(): |
50 |
if engine is None: |
51 |
# They've used a backend we don't support
|
52 |
sys.stderr.write( |
53 |
( |
54 |
"There is no South database module for your database backend '%s'. " + \
|
55 |
"Please either choose a supported database, check for " + \
|
56 |
"SOUTH_DATABASE_ADAPTER[S] settings, " + \
|
57 |
"or remove South from INSTALLED_APPS.\n"
|
58 |
) % (settings.DATABASES[alias]['ENGINE'],)
|
59 |
) |
60 |
sys.exit(1)
|
61 |
|
62 |
# Now, turn that into a dict of <alias: south db module>
|
63 |
dbs = {} |
64 |
try:
|
65 |
for alias, module_name in db_engines.items(): |
66 |
module = __import__(module_name, {}, {}, ['']) |
67 |
dbs[alias] = module.DatabaseOperations(alias) |
68 |
except ImportError: |
69 |
# This error should only be triggered on 1.1 and below.
|
70 |
sys.stderr.write( |
71 |
( |
72 |
"There is no South database module '%s' for your database. " + \
|
73 |
"Please either choose a supported database, check for " + \
|
74 |
"SOUTH_DATABASE_ADAPTER[S] settings, " + \
|
75 |
"or remove South from INSTALLED_APPS.\n"
|
76 |
) % (module_name,) |
77 |
) |
78 |
sys.exit(1)
|
79 |
|
80 |
# Finally, to make old migrations work, keep 'db' around as the default database
|
81 |
db = dbs[DEFAULT_DB_ALIAS] |