mirror of
https://github.com/django/django.git
synced 2025-03-06 07:22:32 +00:00
Fixed #25196 -- Normalized database representations in test database messages.
Left over Oracle mostly as-is since it's more complicated.
This commit is contained in:
parent
53e89ce2e7
commit
afe777639c
@ -39,15 +39,14 @@ class BaseDatabaseCreation(object):
|
|||||||
test_database_name = self._get_test_db_name()
|
test_database_name = self._get_test_db_name()
|
||||||
|
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
test_db_repr = ''
|
|
||||||
action = 'Creating'
|
action = 'Creating'
|
||||||
if verbosity >= 2:
|
|
||||||
test_db_repr = " ('%s')" % test_database_name
|
|
||||||
if keepdb:
|
if keepdb:
|
||||||
action = "Using existing"
|
action = "Using existing"
|
||||||
|
|
||||||
print("%s test database for alias '%s'%s..." % (
|
print("%s test database for alias %s..." % (
|
||||||
action, self.connection.alias, test_db_repr))
|
action,
|
||||||
|
self._get_database_display_str(verbosity, test_database_name),
|
||||||
|
))
|
||||||
|
|
||||||
# We could skip this call if keepdb is True, but we instead
|
# We could skip this call if keepdb is True, but we instead
|
||||||
# give it the keepdb param. This is to handle the case
|
# give it the keepdb param. This is to handle the case
|
||||||
@ -132,6 +131,15 @@ class BaseDatabaseCreation(object):
|
|||||||
for obj in serializers.deserialize("json", data, using=self.connection.alias):
|
for obj in serializers.deserialize("json", data, using=self.connection.alias):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
|
def _get_database_display_str(self, verbosity, database_name):
|
||||||
|
"""
|
||||||
|
Return display string for a database for use in various actions.
|
||||||
|
"""
|
||||||
|
return "'%s'%s" % (
|
||||||
|
self.connection.alias,
|
||||||
|
(" ('%s')" % database_name) if verbosity >= 2 else '',
|
||||||
|
)
|
||||||
|
|
||||||
def _get_test_db_name(self):
|
def _get_test_db_name(self):
|
||||||
"""
|
"""
|
||||||
Internal implementation - returns the name of the test DB that will be
|
Internal implementation - returns the name of the test DB that will be
|
||||||
@ -173,8 +181,9 @@ class BaseDatabaseCreation(object):
|
|||||||
if autoclobber or confirm == 'yes':
|
if autoclobber or confirm == 'yes':
|
||||||
try:
|
try:
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..."
|
print("Destroying old test database for alias %s..." % (
|
||||||
% self.connection.alias)
|
self._get_database_display_str(verbosity, test_database_name),
|
||||||
|
))
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"DROP DATABASE %s" % qn(test_database_name))
|
"DROP DATABASE %s" % qn(test_database_name))
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
@ -197,13 +206,13 @@ class BaseDatabaseCreation(object):
|
|||||||
source_database_name = self.connection.settings_dict['NAME']
|
source_database_name = self.connection.settings_dict['NAME']
|
||||||
|
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
test_db_repr = ''
|
|
||||||
action = 'Cloning test database'
|
action = 'Cloning test database'
|
||||||
if verbosity >= 2:
|
|
||||||
test_db_repr = " ('%s')" % source_database_name
|
|
||||||
if keepdb:
|
if keepdb:
|
||||||
action = 'Using existing clone'
|
action = 'Using existing clone'
|
||||||
print("%s for alias '%s'%s..." % (action, self.connection.alias, test_db_repr))
|
print("%s for alias %s..." % (
|
||||||
|
action,
|
||||||
|
self._get_database_display_str(verbosity, source_database_name),
|
||||||
|
))
|
||||||
|
|
||||||
# We could skip this call if keepdb is True, but we instead
|
# We could skip this call if keepdb is True, but we instead
|
||||||
# give it the keepdb param. See create_test_db for details.
|
# give it the keepdb param. See create_test_db for details.
|
||||||
@ -241,14 +250,13 @@ class BaseDatabaseCreation(object):
|
|||||||
test_database_name = self.get_test_db_clone_settings(number)['NAME']
|
test_database_name = self.get_test_db_clone_settings(number)['NAME']
|
||||||
|
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
test_db_repr = ''
|
|
||||||
action = 'Destroying'
|
action = 'Destroying'
|
||||||
if verbosity >= 2:
|
|
||||||
test_db_repr = " ('%s')" % test_database_name
|
|
||||||
if keepdb:
|
if keepdb:
|
||||||
action = 'Preserving'
|
action = 'Preserving'
|
||||||
print("%s test database for alias '%s'%s..." % (
|
print("%s test database for alias %s..." % (
|
||||||
action, self.connection.alias, test_db_repr))
|
action,
|
||||||
|
self._get_database_display_str(verbosity, test_database_name),
|
||||||
|
))
|
||||||
|
|
||||||
# if we want to preserve the database
|
# if we want to preserve the database
|
||||||
# skip the actual destroying piece.
|
# skip the actual destroying piece.
|
||||||
|
@ -30,7 +30,9 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..." % self.connection.alias)
|
print("Destroying old test database for alias %s..." % (
|
||||||
|
self._get_database_display_str(target_database_name, verbosity),
|
||||||
|
))
|
||||||
cursor.execute("DROP DATABASE %s" % qn(target_database_name))
|
cursor.execute("DROP DATABASE %s" % qn(target_database_name))
|
||||||
cursor.execute("CREATE DATABASE %s" % qn(target_database_name))
|
cursor.execute("CREATE DATABASE %s" % qn(target_database_name))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -48,7 +48,7 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
"Type 'yes' to delete it, or 'no' to cancel: " % parameters['user'])
|
"Type 'yes' to delete it, or 'no' to cancel: " % parameters['user'])
|
||||||
if autoclobber or confirm == 'yes':
|
if autoclobber or confirm == 'yes':
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..." % self.connection.alias)
|
print("Destroying old test database for alias '%s'..." % self.connection.alias)
|
||||||
try:
|
try:
|
||||||
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
||||||
except DatabaseError as e:
|
except DatabaseError as e:
|
||||||
@ -149,7 +149,7 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
try:
|
try:
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..." % self.connection.alias)
|
print("Destroying old test database for alias '%s'..." % self.connection.alias)
|
||||||
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stderr.write("Got an error destroying the test database: %s\n" % e)
|
sys.stderr.write("Got an error destroying the test database: %s\n" % e)
|
||||||
|
@ -32,7 +32,9 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..." % self.connection.alias)
|
print("Destroying old test database for alias %s..." % (
|
||||||
|
self._get_database_display_str(target_database_name, verbosity),
|
||||||
|
))
|
||||||
cursor.execute("DROP DATABASE %s" % qn(target_database_name))
|
cursor.execute("DROP DATABASE %s" % qn(target_database_name))
|
||||||
cursor.execute("CREATE DATABASE %s WITH TEMPLATE %s" % (
|
cursor.execute("CREATE DATABASE %s WITH TEMPLATE %s" % (
|
||||||
qn(target_database_name), qn(source_database_name)))
|
qn(target_database_name), qn(source_database_name)))
|
||||||
|
@ -30,7 +30,9 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
if not self.connection.is_in_memory_db(test_database_name):
|
if not self.connection.is_in_memory_db(test_database_name):
|
||||||
# Erase the old test database
|
# Erase the old test database
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..." % self.connection.alias)
|
print("Destroying old test database for alias %s..." % (
|
||||||
|
self._get_database_display_str(verbosity, test_database_name),
|
||||||
|
))
|
||||||
if os.access(test_database_name, os.F_OK):
|
if os.access(test_database_name, os.F_OK):
|
||||||
if not autoclobber:
|
if not autoclobber:
|
||||||
confirm = input(
|
confirm = input(
|
||||||
@ -69,7 +71,9 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
if keepdb:
|
if keepdb:
|
||||||
return
|
return
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print("Destroying old test database '%s'..." % target_database_name)
|
print("Destroying old test database for alias %s..." % (
|
||||||
|
self._get_database_display_str(verbosity, target_database_name),
|
||||||
|
))
|
||||||
try:
|
try:
|
||||||
os.remove(target_database_name)
|
os.remove(target_database_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user