mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
[soc2009/multidb] Updated several strings and internal API names to be more consistant and descriptive
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@10897 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
15d405077e
commit
f4bcbbfa8b
2
TODO.TXT
2
TODO.TXT
@ -13,6 +13,8 @@ that need to be done. I'm trying to be as granular as possible.
|
|||||||
|
|
||||||
The remaining items will be fixed as the code for them enters the code base.
|
The remaining items will be fixed as the code for them enters the code base.
|
||||||
|
|
||||||
|
Replace old instances of :setting:`DATABASE_` with a new tag or something.
|
||||||
|
|
||||||
|
|
||||||
3) Update all management commands in the following way:
|
3) Update all management commands in the following way:
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ class Command(LabelCommand):
|
|||||||
|
|
||||||
option_list = LabelCommand.option_list + (
|
option_list = LabelCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to install the cache table to.'),
|
default='default', help='Nominates a specific database to install '
|
||||||
|
'the cache table to. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
requires_model_validation = False
|
requires_model_validation = False
|
||||||
|
@ -9,7 +9,8 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to connection to.'),
|
default='default', help='Nominates a database to open a shell for.'
|
||||||
|
' Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
requires_model_validation = False
|
requires_model_validation = False
|
||||||
|
@ -15,7 +15,8 @@ class Command(NoArgsCommand):
|
|||||||
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
||||||
help='Tells Django to NOT prompt the user for input of any kind.'),
|
help='Tells Django to NOT prompt the user for input of any kind.'),
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='', help='Selects what database to flush.'),
|
default='', help='Nominates a database to flush. Defaults to '
|
||||||
|
'flushing all databases.'),
|
||||||
)
|
)
|
||||||
help = "Executes ``sqlflush`` on the current database."
|
help = "Executes ``sqlflush`` on the current database."
|
||||||
|
|
||||||
@ -24,11 +25,11 @@ class Command(NoArgsCommand):
|
|||||||
dbs = connections.all()
|
dbs = connections.all()
|
||||||
else:
|
else:
|
||||||
dbs = [options['database']]
|
dbs = [options['database']]
|
||||||
for connection in dbs:
|
|
||||||
verbosity = int(options.get('verbosity', 1))
|
|
||||||
interactive = options.get('interactive')
|
|
||||||
|
|
||||||
self.style = no_style()
|
verbosity = int(options.get('verbosity', 1))
|
||||||
|
interactive = options.get('interactive')
|
||||||
|
|
||||||
|
self.style = no_style()
|
||||||
|
|
||||||
# Import the 'management' module within each installed app, to register
|
# Import the 'management' module within each installed app, to register
|
||||||
# dispatcher events.
|
# dispatcher events.
|
||||||
@ -73,5 +74,50 @@ class Command(NoArgsCommand):
|
|||||||
# Reinstall the initial_data fixture.
|
# Reinstall the initial_data fixture.
|
||||||
call_command('loaddata', 'initial_data', **options)
|
call_command('loaddata', 'initial_data', **options)
|
||||||
|
|
||||||
|
for app_name in settings.INSTALLED_APPS:
|
||||||
|
try:
|
||||||
|
import_module('.management', app_name)
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for connection in dbs:
|
||||||
|
|
||||||
|
# Import the 'management' module within each installed app, to register
|
||||||
|
# dispatcher events.
|
||||||
|
sql_list = sql_flush(self.style, connection, only_django=True)
|
||||||
|
|
||||||
|
if interactive:
|
||||||
|
confirm = raw_input("""You have requested a flush of the database.
|
||||||
|
This will IRREVERSIBLY DESTROY all data currently in the %r database,
|
||||||
|
and return each table to the state it was in after syncdb.
|
||||||
|
Are you sure you want to do this?
|
||||||
|
|
||||||
|
Type 'yes' to continue, or 'no' to cancel: """ % connection.settings_dict['DATABASE_NAME'])
|
||||||
|
else:
|
||||||
|
confirm = 'yes'
|
||||||
|
|
||||||
|
if confirm == 'yes':
|
||||||
|
try:
|
||||||
|
cursor = connection.cursor()
|
||||||
|
for sql in sql_list:
|
||||||
|
cursor.execute(sql)
|
||||||
|
except Exception, e:
|
||||||
|
transaction.rollback_unless_managed()
|
||||||
|
raise CommandError("""Database %s couldn't be flushed. Possible reasons:
|
||||||
|
* The database isn't running or isn't configured correctly.
|
||||||
|
* At least one of the expected database tables doesn't exist.
|
||||||
|
* The SQL was invalid.
|
||||||
|
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
|
||||||
|
The full error: %s""" % (connection.settings_dict.DATABASE_NAME, e))
|
||||||
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
|
# Emit the post sync signal. This allows individual
|
||||||
|
# applications to respond as if the database had been
|
||||||
|
# sync'd from scratch.
|
||||||
|
emit_post_sync_signal(models.get_models(), verbosity, interactive, connection)
|
||||||
|
|
||||||
|
# Reinstall the initial_data fixture.
|
||||||
|
call_command('loaddata', 'initial_data', **options)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "Flush cancelled."
|
print "Flush cancelled."
|
||||||
|
@ -9,7 +9,8 @@ class Command(NoArgsCommand):
|
|||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
option_list = NoArgsCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to introspect.'),
|
default='default', help='Nominates a database to introspect. '
|
||||||
|
'Defaults to using the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
requires_model_validation = False
|
requires_model_validation = False
|
||||||
|
@ -11,7 +11,8 @@ class Command(AppCommand):
|
|||||||
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
||||||
help='Tells Django to NOT prompt the user for input of any kind.'),
|
help='Tells Django to NOT prompt the user for input of any kind.'),
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='', help='Selects what database reset.'),
|
default='', help='Nominates a database to reset. Defaults to '
|
||||||
|
'reseting all databases.'),
|
||||||
)
|
)
|
||||||
help = "Executes ``sqlreset`` for the given app(s) in the current database."
|
help = "Executes ``sqlreset`` for the given app(s) in the current database."
|
||||||
args = '[appname ...]'
|
args = '[appname ...]'
|
||||||
@ -23,10 +24,11 @@ class Command(AppCommand):
|
|||||||
dbs = connections.all()
|
dbs = connections.all()
|
||||||
else:
|
else:
|
||||||
dbs = [options['database']]
|
dbs = [options['database']]
|
||||||
for connection in dbs:
|
|
||||||
app_name = app.__name__.split('.')[-2]
|
|
||||||
|
|
||||||
self.style = no_style()
|
app_name = app.__name__.split('.')[-2]
|
||||||
|
self.style = no_style()
|
||||||
|
|
||||||
|
for connection in dbs:
|
||||||
|
|
||||||
sql_list = sql_reset(app, self.style, connection)
|
sql_list = sql_reset(app, self.style, connection)
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -9,7 +9,8 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -9,7 +9,8 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -9,7 +9,8 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -9,7 +9,8 @@ class Command(NoArgsCommand):
|
|||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
option_list = NoArgsCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -9,7 +9,8 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -9,7 +9,8 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
|
'for. Defaults to the "default" database.'),
|
||||||
)
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
@ -8,8 +8,9 @@ class Command(AppCommand):
|
|||||||
|
|
||||||
option_list = AppCommand.option_list + (
|
option_list = AppCommand.option_list + (
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='default', help='Selects what database to print the SQL for.'),
|
default='default', help='Nominates a database to print the SQL '
|
||||||
)
|
'for. Defaults to the "default" database.'),
|
||||||
|
)
|
||||||
|
|
||||||
output_transaction = True
|
output_transaction = True
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ class Command(NoArgsCommand):
|
|||||||
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
||||||
help='Tells Django to NOT prompt the user for input of any kind.'),
|
help='Tells Django to NOT prompt the user for input of any kind.'),
|
||||||
make_option('--database', action='store', dest='database',
|
make_option('--database', action='store', dest='database',
|
||||||
default='', help='Selects what database to flush.'),
|
default='', help='Nominates a database to sync. Defaults to the '
|
||||||
|
'"default" database.'),
|
||||||
)
|
)
|
||||||
help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
|
help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
|
||||||
|
|
||||||
@ -34,27 +35,27 @@ class Command(NoArgsCommand):
|
|||||||
dbs = connections.all()
|
dbs = connections.all()
|
||||||
else:
|
else:
|
||||||
dbs = [connections[options['database']]]
|
dbs = [connections[options['database']]]
|
||||||
|
|
||||||
|
# Import the 'management' module within each installed app, to register
|
||||||
|
# dispatcher events.
|
||||||
|
for app_name in settings.INSTALLED_APPS:
|
||||||
|
try:
|
||||||
|
import_module('.management', app_name)
|
||||||
|
except ImportError, exc:
|
||||||
|
# This is slightly hackish. We want to ignore ImportErrors
|
||||||
|
# if the "management" module itself is missing -- but we don't
|
||||||
|
# want to ignore the exception if the management module exists
|
||||||
|
# but raises an ImportError for some reason. The only way we
|
||||||
|
# can do this is to check the text of the exception. Note that
|
||||||
|
# we're a bit broad in how we check the text, because different
|
||||||
|
# Python implementations may not use the same text.
|
||||||
|
# CPython uses the text "No module named management"
|
||||||
|
# PyPy uses "No module named myproject.myapp.management"
|
||||||
|
msg = exc.args[0]
|
||||||
|
if not msg.startswith('No module named') or 'management' not in msg:
|
||||||
|
raise
|
||||||
|
|
||||||
for connection in dbs:
|
for connection in dbs:
|
||||||
|
|
||||||
# Import the 'management' module within each installed app, to register
|
|
||||||
# dispatcher events.
|
|
||||||
for app_name in settings.INSTALLED_APPS:
|
|
||||||
try:
|
|
||||||
import_module('.management', app_name)
|
|
||||||
except ImportError, exc:
|
|
||||||
# This is slightly hackish. We want to ignore ImportErrors
|
|
||||||
# if the "management" module itself is missing -- but we don't
|
|
||||||
# want to ignore the exception if the management module exists
|
|
||||||
# but raises an ImportError for some reason. The only way we
|
|
||||||
# can do this is to check the text of the exception. Note that
|
|
||||||
# we're a bit broad in how we check the text, because different
|
|
||||||
# Python implementations may not use the same text.
|
|
||||||
# CPython uses the text "No module named management"
|
|
||||||
# PyPy uses "No module named myproject.myapp.management"
|
|
||||||
msg = exc.args[0]
|
|
||||||
if not msg.startswith('No module named') or 'management' not in msg:
|
|
||||||
raise
|
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
# Get a list of already installed *models* so that references work right.
|
# Get a list of already installed *models* so that references work right.
|
||||||
@ -154,15 +155,9 @@ class Command(NoArgsCommand):
|
|||||||
else:
|
else:
|
||||||
transaction.commit_unless_managed()
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
<<<<<<< HEAD:django/core/management/commands/syncdb.py
|
|
||||||
# Install the 'initial_data' fixture, using format discovery
|
|
||||||
from django.core.management import call_command
|
|
||||||
call_command('loaddata', 'initial_data', verbosity=verbosity)
|
|
||||||
=======
|
|
||||||
# Install the 'initial_data' fixture, using format discovery
|
# Install the 'initial_data' fixture, using format discovery
|
||||||
# FIXME we only load the fixture data for one DB right now, since we
|
# FIXME we only load the fixture data for one DB right now, since we
|
||||||
# can't control what DB it does into, once we can control this we
|
# can't control what DB it does into, once we can control this we
|
||||||
# should move it back into the DB loop
|
# should move it back into the DB loop
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
call_command('loaddata', 'initial_data', verbosity=verbosity)
|
call_command('loaddata', 'initial_data', verbosity=verbosity)
|
||||||
>>>>>>> 2c764d3ff7cb665ec919d1f3e2977587752c6f2c:django/core/management/commands/syncdb.py
|
|
||||||
|
@ -288,8 +288,6 @@ class Constraint(object):
|
|||||||
try:
|
try:
|
||||||
if self.field:
|
if self.field:
|
||||||
params = self.field.get_db_prep_lookup(lookup_type, value)
|
params = self.field.get_db_prep_lookup(lookup_type, value)
|
||||||
# FIXME, we're using the global connection object here, once a
|
|
||||||
# WhereNode know's it's connection we should pass that through
|
|
||||||
db_type = self.field.db_type(connection)
|
db_type = self.field.db_type(connection)
|
||||||
else:
|
else:
|
||||||
# This branch is used at times when we add a comparison to NULL
|
# This branch is used at times when we add a comparison to NULL
|
||||||
|
@ -36,7 +36,11 @@ class ConnectionHandler(object):
|
|||||||
self.databases = databases
|
self.databases = databases
|
||||||
self._connections = {}
|
self._connections = {}
|
||||||
|
|
||||||
def check_connection(self, alias):
|
def ensure_defaults(self, alias):
|
||||||
|
"""
|
||||||
|
Puts the defaults into the settings dictionary for a given connection
|
||||||
|
where no settings is provided.
|
||||||
|
"""
|
||||||
conn = self.databases[alias]
|
conn = self.databases[alias]
|
||||||
conn.setdefault('DATABASE_ENGINE', 'dummy')
|
conn.setdefault('DATABASE_ENGINE', 'dummy')
|
||||||
conn.setdefault('DATABASE_OPTIONS', {})
|
conn.setdefault('DATABASE_OPTIONS', {})
|
||||||
@ -52,7 +56,7 @@ class ConnectionHandler(object):
|
|||||||
if alias in self._connections:
|
if alias in self._connections:
|
||||||
return self._connections[alias]
|
return self._connections[alias]
|
||||||
|
|
||||||
self.check_connection(alias)
|
self.ensure_defaults(alias)
|
||||||
db = self.databases[alias]
|
db = self.databases[alias]
|
||||||
backend = load_backend(db['DATABASE_ENGINE'])
|
backend = load_backend(db['DATABASE_ENGINE'])
|
||||||
conn = backend.DatabaseWrapper(db)
|
conn = backend.DatabaseWrapper(db)
|
||||||
@ -63,4 +67,4 @@ class ConnectionHandler(object):
|
|||||||
return iter(self.databases)
|
return iter(self.databases)
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
return [self[alias] for alias in self.databases]
|
return [self[alias] for alias in self]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user