Removed legacy handing for `settings.DATABAS_*` and using short-form references to the included database backends.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15959 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e57cc90c16
commit
9b3aaae255
|
@ -8,59 +8,9 @@ __all__ = ('backend', 'connection', 'connections', 'router', 'DatabaseError',
|
|||
'IntegrityError', 'DEFAULT_DB_ALIAS')
|
||||
|
||||
|
||||
# For backwards compatibility - Port any old database settings over to
|
||||
# the new values.
|
||||
if not settings.DATABASES:
|
||||
if settings.DATABASE_ENGINE:
|
||||
import warnings
|
||||
warnings.warn(
|
||||
"settings.DATABASE_* is deprecated; use settings.DATABASES instead.",
|
||||
DeprecationWarning
|
||||
)
|
||||
|
||||
settings.DATABASES[DEFAULT_DB_ALIAS] = {
|
||||
'ENGINE': settings.DATABASE_ENGINE,
|
||||
'HOST': settings.DATABASE_HOST,
|
||||
'NAME': settings.DATABASE_NAME,
|
||||
'OPTIONS': settings.DATABASE_OPTIONS,
|
||||
'PASSWORD': settings.DATABASE_PASSWORD,
|
||||
'PORT': settings.DATABASE_PORT,
|
||||
'USER': settings.DATABASE_USER,
|
||||
'TEST_CHARSET': settings.TEST_DATABASE_CHARSET,
|
||||
'TEST_COLLATION': settings.TEST_DATABASE_COLLATION,
|
||||
'TEST_NAME': settings.TEST_DATABASE_NAME,
|
||||
}
|
||||
|
||||
if DEFAULT_DB_ALIAS not in settings.DATABASES:
|
||||
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
|
||||
|
||||
for alias, database in settings.DATABASES.items():
|
||||
if 'ENGINE' not in database:
|
||||
raise ImproperlyConfigured("You must specify a 'ENGINE' for database '%s'" % alias)
|
||||
if database['ENGINE'] in ("postgresql", "postgresql_psycopg2", "sqlite3", "mysql", "oracle"):
|
||||
import warnings
|
||||
if 'django.contrib.gis' in settings.INSTALLED_APPS:
|
||||
warnings.warn(
|
||||
"django.contrib.gis is now implemented as a full database backend. "
|
||||
"Modify ENGINE in the %s database configuration to select "
|
||||
"a backend from 'django.contrib.gis.db.backends'" % alias,
|
||||
DeprecationWarning
|
||||
)
|
||||
if database['ENGINE'] == 'postgresql_psycopg2':
|
||||
full_engine = 'django.contrib.gis.db.backends.postgis'
|
||||
elif database['ENGINE'] == 'sqlite3':
|
||||
full_engine = 'django.contrib.gis.db.backends.spatialite'
|
||||
else:
|
||||
full_engine = 'django.contrib.gis.db.backends.%s' % database['ENGINE']
|
||||
else:
|
||||
warnings.warn(
|
||||
"Short names for ENGINE in database configurations are deprecated. "
|
||||
"Prepend %s.ENGINE with 'django.db.backends.'" % alias,
|
||||
DeprecationWarning
|
||||
)
|
||||
full_engine = "django.db.backends.%s" % database['ENGINE']
|
||||
database['ENGINE'] = full_engine
|
||||
|
||||
connections = ConnectionHandler(settings.DATABASES)
|
||||
|
||||
router = ConnectionRouter(settings.DATABASE_ROUTERS)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import inspect
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -19,15 +18,6 @@ class IntegrityError(DatabaseError):
|
|||
|
||||
|
||||
def load_backend(backend_name):
|
||||
try:
|
||||
module = import_module('.base', 'django.db.backends.%s' % backend_name)
|
||||
import warnings
|
||||
warnings.warn(
|
||||
"Short names for DATABASE_ENGINE are deprecated; prepend with 'django.db.backends.'",
|
||||
DeprecationWarning
|
||||
)
|
||||
return module
|
||||
except ImportError, e:
|
||||
# Look for a fully qualified database backend name
|
||||
try:
|
||||
return import_module('.base', backend_name)
|
||||
|
@ -76,13 +66,11 @@ class ConnectionHandler(object):
|
|||
if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']:
|
||||
conn['ENGINE'] = 'django.db.backends.dummy'
|
||||
conn.setdefault('OPTIONS', {})
|
||||
conn.setdefault('TEST_CHARSET', None)
|
||||
conn.setdefault('TEST_COLLATION', None)
|
||||
conn.setdefault('TEST_NAME', None)
|
||||
conn.setdefault('TEST_MIRROR', None)
|
||||
conn.setdefault('TIME_ZONE', settings.TIME_ZONE)
|
||||
for setting in ('NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
|
||||
for setting in ['NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']:
|
||||
conn.setdefault(setting, '')
|
||||
for setting in ['TEST_CHARSET', 'TEST_COLLATION', 'TEST_NAME', 'TEST_MIRROR']:
|
||||
conn.setdefault(setting, None)
|
||||
|
||||
def __getitem__(self, alias):
|
||||
if alias in self._connections:
|
||||
|
|
Loading…
Reference in New Issue