2012-09-08 02:14:06 +08:00
|
|
|
import hashlib
|
2008-08-11 20:11:25 +08:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from django.conf import settings
|
2012-01-30 16:27:50 +08:00
|
|
|
from django.db.utils import load_backend
|
2012-09-08 03:33:02 +08:00
|
|
|
from django.utils.encoding import force_bytes
|
2013-11-09 16:41:03 +08:00
|
|
|
from django.utils.functional import cached_property
|
2012-08-09 01:08:05 +08:00
|
|
|
from django.utils.six.moves import input
|
2014-06-09 10:30:15 +08:00
|
|
|
from django.utils.six import StringIO
|
|
|
|
from django.db import router
|
|
|
|
from django.apps import apps
|
|
|
|
from django.core import serializers
|
2008-08-11 20:11:25 +08:00
|
|
|
|
2013-09-17 00:52:05 +08:00
|
|
|
from .utils import truncate_name
|
2013-02-08 17:01:56 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
# The prefix to put on the default database name when creating
|
|
|
|
# the test database.
|
|
|
|
TEST_DATABASE_PREFIX = 'test_'
|
2013-11-09 18:21:53 +08:00
|
|
|
NO_DB_ALIAS = '__no_db__'
|
2008-08-11 20:11:25 +08:00
|
|
|
|
2012-01-30 16:27:50 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class BaseDatabaseCreation(object):
|
2007-09-15 00:44:53 +08:00
|
|
|
"""
|
|
|
|
This class encapsulates all backend-specific differences that pertain to
|
|
|
|
database *creation*, such as the column types to use for particular Django
|
2008-08-13 00:06:55 +08:00
|
|
|
Fields, the SQL used to create and destroy tables, and the creation and
|
2008-08-11 20:11:25 +08:00
|
|
|
destruction of test databases.
|
2007-09-15 00:44:53 +08:00
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
data_types = {}
|
2013-09-07 00:18:16 +08:00
|
|
|
data_types_suffix = {}
|
2012-09-08 03:40:59 +08:00
|
|
|
data_type_check_constraints = {}
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def __init__(self, connection):
|
|
|
|
self.connection = connection
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2013-11-09 16:41:03 +08:00
|
|
|
@cached_property
|
|
|
|
def _nodb_connection(self):
|
|
|
|
"""
|
|
|
|
Alternative connection to be used when there is no need to access
|
|
|
|
the main database, specifically for test db creation/deletion.
|
|
|
|
This also prevents the production database from being exposed to
|
|
|
|
potential child threads while (or after) the test database is destroyed.
|
|
|
|
Refs #10868, #17786, #16969.
|
|
|
|
"""
|
|
|
|
settings_dict = self.connection.settings_dict.copy()
|
|
|
|
settings_dict['NAME'] = None
|
|
|
|
backend = load_backend(settings_dict['ENGINE'])
|
|
|
|
nodb_connection = backend.DatabaseWrapper(
|
2013-11-09 22:38:47 +08:00
|
|
|
settings_dict,
|
|
|
|
alias=NO_DB_ALIAS,
|
|
|
|
allow_thread_sharing=False)
|
2013-11-09 16:41:03 +08:00
|
|
|
return nodb_connection
|
|
|
|
|
2012-08-02 22:08:39 +08:00
|
|
|
@classmethod
|
|
|
|
def _digest(cls, *args):
|
2009-06-15 07:03:01 +08:00
|
|
|
"""
|
|
|
|
Generates a 32-bit digest of a set of arguments that can be used to
|
|
|
|
shorten identifying names.
|
|
|
|
"""
|
2012-09-08 02:14:06 +08:00
|
|
|
h = hashlib.md5()
|
|
|
|
for arg in args:
|
2012-09-08 03:33:02 +08:00
|
|
|
h.update(force_bytes(arg))
|
2012-09-08 02:14:06 +08:00
|
|
|
return h.hexdigest()[:8]
|
Fixed #9253 -- Modified the method used to generate constraint names so that it is consistent regardless of machine word size.
NOTE: This change is backwards incompatible for some users.
If you are using a 32-bit platform, you will observe no differences as a
result of this change. However, users on 64-bit platforms may experience
some problems using the `reset` management command.
Prior to this change, 64-bit platforms would generate a 64-bit, 16 character
digest in the constraint name; for example:
ALTER TABLE `myapp_sometable` ADD CONSTRAINT `object_id_refs_id_5e8f10c132091d1e` FOREIGN KEY ...
Following this change, all platforms, regardless of word size, will
generate a 32-bit, 8 character digest in the constraint name; for example:
ALTER TABLE `myapp_sometable` ADD CONSTRAINT `object_id_refs_id_32091d1e` FOREIGN KEY ...
As a result of this change, you will not be able to use the `reset`
management command on any table created with 64-bit constraints. This
is because the the new generated name will not match the historically
generated name; as a result, the SQL constructed by the `reset` command
will be invalid.
If you need to reset an application that was created with 64-bit
constraints, you will need to manually drop the old constraint prior
to invoking `reset`.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10966 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-06-09 20:59:41 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def sql_create_model(self, model, style, known_models=set()):
|
|
|
|
"""
|
|
|
|
Returns the SQL required to create a single model, as a tuple of:
|
|
|
|
(list_of_sql, pending_references_dict)
|
|
|
|
"""
|
|
|
|
opts = model._meta
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
if not opts.managed or opts.proxy or opts.swapped:
|
2009-03-09 11:35:02 +08:00
|
|
|
return [], {}
|
2008-08-11 20:11:25 +08:00
|
|
|
final_output = []
|
|
|
|
table_output = []
|
|
|
|
pending_references = {}
|
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
for f in opts.local_fields:
|
2014-09-04 23:32:51 +08:00
|
|
|
db_params = f.db_parameters(connection=self.connection)
|
|
|
|
col_type = db_params['type']
|
|
|
|
if db_params['check']:
|
|
|
|
col_type = '%s CHECK (%s)' % (col_type, db_params['check'])
|
2013-09-07 00:18:16 +08:00
|
|
|
col_type_suffix = f.db_type_suffix(connection=self.connection)
|
2008-08-11 20:11:25 +08:00
|
|
|
tablespace = f.db_tablespace or opts.db_tablespace
|
|
|
|
if col_type is None:
|
|
|
|
# Skip ManyToManyFields, because they're not represented as
|
|
|
|
# database columns in this table.
|
|
|
|
continue
|
|
|
|
# Make the definition (e.g. 'foo VARCHAR(30)') for this field.
|
|
|
|
field_output = [style.SQL_FIELD(qn(f.column)),
|
|
|
|
style.SQL_COLTYPE(col_type)]
|
2012-04-30 00:25:46 +08:00
|
|
|
# Oracle treats the empty string ('') as null, so coerce the null
|
|
|
|
# option whenever '' is a possible value.
|
|
|
|
null = f.null
|
|
|
|
if (f.empty_strings_allowed and not f.primary_key and
|
|
|
|
self.connection.features.interprets_empty_strings_as_nulls):
|
|
|
|
null = True
|
|
|
|
if not null:
|
2009-01-06 09:56:13 +08:00
|
|
|
field_output.append(style.SQL_KEYWORD('NOT NULL'))
|
2008-08-11 20:11:25 +08:00
|
|
|
if f.primary_key:
|
|
|
|
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
|
|
|
|
elif f.unique:
|
|
|
|
field_output.append(style.SQL_KEYWORD('UNIQUE'))
|
|
|
|
if tablespace and f.unique:
|
|
|
|
# We must specify the index tablespace inline, because we
|
|
|
|
# won't be generating a CREATE INDEX statement for this field.
|
2012-01-30 16:27:50 +08:00
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(
|
|
|
|
tablespace, inline=True)
|
2011-10-15 05:49:43 +08:00
|
|
|
if tablespace_sql:
|
|
|
|
field_output.append(tablespace_sql)
|
2013-02-21 03:27:32 +08:00
|
|
|
if f.rel and f.db_constraint:
|
2012-01-30 16:27:50 +08:00
|
|
|
ref_output, pending = self.sql_for_inline_foreign_key_references(
|
2013-01-28 17:17:56 +08:00
|
|
|
model, f, known_models, style)
|
2008-08-11 20:11:25 +08:00
|
|
|
if pending:
|
2012-01-30 16:27:50 +08:00
|
|
|
pending_references.setdefault(f.rel.to, []).append(
|
|
|
|
(model, f))
|
2008-08-11 20:11:25 +08:00
|
|
|
else:
|
|
|
|
field_output.extend(ref_output)
|
2013-09-07 00:18:16 +08:00
|
|
|
if col_type_suffix:
|
|
|
|
field_output.append(style.SQL_KEYWORD(col_type_suffix))
|
2008-08-11 20:11:25 +08:00
|
|
|
table_output.append(' '.join(field_output))
|
|
|
|
for field_constraints in opts.unique_together:
|
2012-01-30 16:27:50 +08:00
|
|
|
table_output.append(style.SQL_KEYWORD('UNIQUE') + ' (%s)' %
|
|
|
|
", ".join(
|
|
|
|
[style.SQL_FIELD(qn(opts.get_field(f).column))
|
|
|
|
for f in field_constraints]))
|
2008-08-11 20:11:25 +08:00
|
|
|
|
2012-01-30 16:27:50 +08:00
|
|
|
full_statement = [style.SQL_KEYWORD('CREATE TABLE') + ' ' +
|
|
|
|
style.SQL_TABLE(qn(opts.db_table)) + ' (']
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
for i, line in enumerate(table_output): # Combine and add commas.
|
2012-01-30 16:27:50 +08:00
|
|
|
full_statement.append(
|
2013-05-27 10:47:50 +08:00
|
|
|
' %s%s' % (line, ',' if i < len(table_output) - 1 else ''))
|
2008-08-11 20:11:25 +08:00
|
|
|
full_statement.append(')')
|
|
|
|
if opts.db_tablespace:
|
2012-01-30 16:27:50 +08:00
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(
|
|
|
|
opts.db_tablespace)
|
2011-10-15 05:49:43 +08:00
|
|
|
if tablespace_sql:
|
|
|
|
full_statement.append(tablespace_sql)
|
2008-08-11 20:11:25 +08:00
|
|
|
full_statement.append(';')
|
|
|
|
final_output.append('\n'.join(full_statement))
|
|
|
|
|
|
|
|
if opts.has_auto_field:
|
2012-01-30 16:27:50 +08:00
|
|
|
# Add any extra SQL needed to support auto-incrementing primary
|
|
|
|
# keys.
|
2008-08-11 20:11:25 +08:00
|
|
|
auto_column = opts.auto_field.db_column or opts.auto_field.name
|
2012-01-30 16:27:50 +08:00
|
|
|
autoinc_sql = self.connection.ops.autoinc_sql(opts.db_table,
|
|
|
|
auto_column)
|
2008-08-11 20:11:25 +08:00
|
|
|
if autoinc_sql:
|
|
|
|
for stmt in autoinc_sql:
|
|
|
|
final_output.append(stmt)
|
|
|
|
|
|
|
|
return final_output, pending_references
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2013-01-28 17:17:56 +08:00
|
|
|
def sql_for_inline_foreign_key_references(self, model, field, known_models, style):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Return the SQL snippet defining the foreign key reference for a field.
|
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
qn = self.connection.ops.quote_name
|
2013-01-28 17:17:56 +08:00
|
|
|
rel_to = field.rel.to
|
|
|
|
if rel_to in known_models or rel_to == model:
|
2012-01-30 16:27:50 +08:00
|
|
|
output = [style.SQL_KEYWORD('REFERENCES') + ' ' +
|
2013-01-28 17:17:56 +08:00
|
|
|
style.SQL_TABLE(qn(rel_to._meta.db_table)) + ' (' +
|
|
|
|
style.SQL_FIELD(qn(rel_to._meta.get_field(
|
2012-01-30 16:27:50 +08:00
|
|
|
field.rel.field_name).column)) + ')' +
|
2008-08-11 20:11:25 +08:00
|
|
|
self.connection.ops.deferrable_sql()
|
|
|
|
]
|
|
|
|
pending = False
|
|
|
|
else:
|
|
|
|
# We haven't yet created the table to which this field
|
|
|
|
# is related, so save it for later.
|
|
|
|
output = []
|
|
|
|
pending = True
|
2008-08-13 00:06:55 +08:00
|
|
|
|
|
|
|
return output, pending
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def sql_for_pending_references(self, model, style, pending_references):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Returns any ALTER TABLE statements to add constraints after the fact.
|
|
|
|
"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
opts = model._meta
|
2013-08-02 02:09:47 +08:00
|
|
|
if not opts.managed or opts.swapped:
|
2009-03-09 11:35:02 +08:00
|
|
|
return []
|
2008-08-11 20:11:25 +08:00
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
final_output = []
|
|
|
|
if model in pending_references:
|
|
|
|
for rel_class, f in pending_references[model]:
|
|
|
|
rel_opts = rel_class._meta
|
|
|
|
r_table = rel_opts.db_table
|
|
|
|
r_col = f.column
|
|
|
|
table = opts.db_table
|
|
|
|
col = opts.get_field(f.rel.field_name).column
|
|
|
|
# For MySQL, r_name must be unique in the first 64 characters.
|
|
|
|
# So we are careful with character usage here.
|
2012-01-30 16:27:50 +08:00
|
|
|
r_name = '%s_refs_%s_%s' % (
|
|
|
|
r_col, col, self._digest(r_table, table))
|
|
|
|
final_output.append(style.SQL_KEYWORD('ALTER TABLE') +
|
|
|
|
' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' %
|
|
|
|
(qn(r_table), qn(truncate_name(
|
|
|
|
r_name, self.connection.ops.max_name_length())),
|
2008-08-11 20:11:25 +08:00
|
|
|
qn(r_col), qn(table), qn(col),
|
|
|
|
self.connection.ops.deferrable_sql()))
|
|
|
|
del pending_references[model]
|
|
|
|
return final_output
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def sql_indexes_for_model(self, model, style):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Returns the CREATE INDEX SQL statements for a single model.
|
|
|
|
"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
|
2009-03-09 11:35:02 +08:00
|
|
|
return []
|
2008-08-11 20:11:25 +08:00
|
|
|
output = []
|
|
|
|
for f in model._meta.local_fields:
|
|
|
|
output.extend(self.sql_indexes_for_field(model, f, style))
|
2012-11-05 02:16:06 +08:00
|
|
|
for fs in model._meta.index_together:
|
|
|
|
fields = [model._meta.get_field_by_name(f)[0] for f in fs]
|
|
|
|
output.extend(self.sql_indexes_for_fields(model, fields, style))
|
2008-08-11 20:11:25 +08:00
|
|
|
return output
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def sql_indexes_for_field(self, model, f, style):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Return the CREATE INDEX SQL statements for a single model field.
|
|
|
|
"""
|
2012-11-05 02:16:06 +08:00
|
|
|
if f.db_index and not f.unique:
|
|
|
|
return self.sql_indexes_for_fields(model, [f], style)
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
def sql_indexes_for_fields(self, model, fields, style):
|
|
|
|
if len(fields) == 1 and fields[0].db_tablespace:
|
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(fields[0].db_tablespace)
|
|
|
|
elif model._meta.db_tablespace:
|
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(model._meta.db_tablespace)
|
2008-08-11 20:11:25 +08:00
|
|
|
else:
|
2012-11-05 02:16:06 +08:00
|
|
|
tablespace_sql = ""
|
|
|
|
if tablespace_sql:
|
|
|
|
tablespace_sql = " " + tablespace_sql
|
|
|
|
|
|
|
|
field_names = []
|
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
for f in fields:
|
|
|
|
field_names.append(style.SQL_FIELD(qn(f.column)))
|
|
|
|
|
|
|
|
index_name = "%s_%s" % (model._meta.db_table, self._digest([f.name for f in fields]))
|
|
|
|
|
|
|
|
return [
|
|
|
|
style.SQL_KEYWORD("CREATE INDEX") + " " +
|
|
|
|
style.SQL_TABLE(qn(truncate_name(index_name, self.connection.ops.max_name_length()))) + " " +
|
|
|
|
style.SQL_KEYWORD("ON") + " " +
|
|
|
|
style.SQL_TABLE(qn(model._meta.db_table)) + " " +
|
|
|
|
"(%s)" % style.SQL_FIELD(", ".join(field_names)) +
|
|
|
|
"%s;" % tablespace_sql,
|
|
|
|
]
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
def sql_destroy_model(self, model, references_to_delete, style):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Return the DROP TABLE and restraint dropping statements for a single
|
|
|
|
model.
|
|
|
|
"""
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
|
2009-03-09 11:35:02 +08:00
|
|
|
return []
|
2008-08-11 20:11:25 +08:00
|
|
|
# Drop the table now
|
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
output = ['%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),
|
|
|
|
style.SQL_TABLE(qn(model._meta.db_table)))]
|
|
|
|
if model in references_to_delete:
|
2012-01-30 16:27:50 +08:00
|
|
|
output.extend(self.sql_remove_table_constraints(
|
|
|
|
model, references_to_delete, style))
|
2008-08-11 20:11:25 +08:00
|
|
|
if model._meta.has_auto_field:
|
|
|
|
ds = self.connection.ops.drop_sequence_sql(model._meta.db_table)
|
|
|
|
if ds:
|
|
|
|
output.append(ds)
|
|
|
|
return output
|
|
|
|
|
2008-08-13 00:06:55 +08:00
|
|
|
def sql_remove_table_constraints(self, model, references_to_delete, style):
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
|
2009-03-09 11:35:02 +08:00
|
|
|
return []
|
2008-08-11 20:11:25 +08:00
|
|
|
output = []
|
2008-08-13 00:06:55 +08:00
|
|
|
qn = self.connection.ops.quote_name
|
2008-08-11 20:11:25 +08:00
|
|
|
for rel_class, f in references_to_delete[model]:
|
|
|
|
table = rel_class._meta.db_table
|
|
|
|
col = f.column
|
|
|
|
r_table = model._meta.db_table
|
|
|
|
r_col = model._meta.get_field(f.rel.field_name).column
|
2012-01-30 16:27:50 +08:00
|
|
|
r_name = '%s_refs_%s_%s' % (
|
|
|
|
col, r_col, self._digest(table, r_table))
|
2013-07-08 08:39:54 +08:00
|
|
|
output.append('%s %s %s %s;' % (
|
|
|
|
style.SQL_KEYWORD('ALTER TABLE'),
|
2008-08-11 20:11:25 +08:00
|
|
|
style.SQL_TABLE(qn(table)),
|
|
|
|
style.SQL_KEYWORD(self.connection.ops.drop_foreignkey_sql()),
|
2012-01-30 16:27:50 +08:00
|
|
|
style.SQL_FIELD(qn(truncate_name(
|
2013-07-08 08:39:54 +08:00
|
|
|
r_name, self.connection.ops.max_name_length())))
|
|
|
|
))
|
2008-08-11 20:11:25 +08:00
|
|
|
del references_to_delete[model]
|
|
|
|
return output
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2013-02-24 00:07:50 +08:00
|
|
|
def sql_destroy_indexes_for_model(self, model, style):
|
|
|
|
"""
|
|
|
|
Returns the DROP INDEX SQL statements for a single model.
|
|
|
|
"""
|
|
|
|
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
|
|
|
|
return []
|
|
|
|
output = []
|
|
|
|
for f in model._meta.local_fields:
|
|
|
|
output.extend(self.sql_destroy_indexes_for_field(model, f, style))
|
|
|
|
for fs in model._meta.index_together:
|
|
|
|
fields = [model._meta.get_field_by_name(f)[0] for f in fs]
|
|
|
|
output.extend(self.sql_destroy_indexes_for_fields(model, fields, style))
|
|
|
|
return output
|
|
|
|
|
|
|
|
def sql_destroy_indexes_for_field(self, model, f, style):
|
|
|
|
"""
|
|
|
|
Return the DROP INDEX SQL statements for a single model field.
|
|
|
|
"""
|
|
|
|
if f.db_index and not f.unique:
|
|
|
|
return self.sql_destroy_indexes_for_fields(model, [f], style)
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
def sql_destroy_indexes_for_fields(self, model, fields, style):
|
|
|
|
if len(fields) == 1 and fields[0].db_tablespace:
|
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(fields[0].db_tablespace)
|
|
|
|
elif model._meta.db_tablespace:
|
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(model._meta.db_tablespace)
|
|
|
|
else:
|
|
|
|
tablespace_sql = ""
|
|
|
|
if tablespace_sql:
|
|
|
|
tablespace_sql = " " + tablespace_sql
|
|
|
|
|
|
|
|
field_names = []
|
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
for f in fields:
|
|
|
|
field_names.append(style.SQL_FIELD(qn(f.column)))
|
|
|
|
|
|
|
|
index_name = "%s_%s" % (model._meta.db_table, self._digest([f.name for f in fields]))
|
|
|
|
|
|
|
|
return [
|
|
|
|
style.SQL_KEYWORD("DROP INDEX") + " " +
|
|
|
|
style.SQL_TABLE(qn(truncate_name(index_name, self.connection.ops.max_name_length()))) + " " +
|
|
|
|
";",
|
|
|
|
]
|
|
|
|
|
2014-06-09 23:12:28 +08:00
|
|
|
def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb=False):
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
|
|
|
Creates a test database, prompting the user for confirmation if the
|
|
|
|
database already exists. Returns the name of the test database created.
|
|
|
|
"""
|
2010-12-22 05:32:59 +08:00
|
|
|
# Don't import django.core.management if it isn't needed.
|
|
|
|
from django.core.management import call_command
|
|
|
|
|
2010-12-09 07:48:28 +08:00
|
|
|
test_database_name = self._get_test_db_name()
|
2008-08-11 20:11:25 +08:00
|
|
|
|
2010-11-22 01:18:26 +08:00
|
|
|
if verbosity >= 1:
|
|
|
|
test_db_repr = ''
|
2014-05-28 05:13:08 +08:00
|
|
|
action = 'Creating'
|
2010-11-22 01:18:26 +08:00
|
|
|
if verbosity >= 2:
|
|
|
|
test_db_repr = " ('%s')" % test_database_name
|
2014-05-28 05:13:08 +08:00
|
|
|
if keepdb:
|
|
|
|
action = "Using existing"
|
2010-11-22 01:18:26 +08:00
|
|
|
|
2014-05-28 05:13:08 +08:00
|
|
|
print("%s test database for alias '%s'%s..." % (
|
|
|
|
action, self.connection.alias, test_db_repr))
|
|
|
|
|
|
|
|
# We could skip this call if keepdb is True, but we instead
|
|
|
|
# give it the keepdb param. This is to handle the case
|
|
|
|
# where the test DB doesn't exist, in which case we need to
|
|
|
|
# create it, then just not destroy it. If we instead skip
|
|
|
|
# this, we will get an exception.
|
|
|
|
self._create_test_db(verbosity, autoclobber, keepdb)
|
2010-12-09 07:48:28 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
self.connection.close()
|
2012-11-27 04:45:21 +08:00
|
|
|
settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
|
2009-12-22 23:18:51 +08:00
|
|
|
self.connection.settings_dict["NAME"] = test_database_name
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2014-06-10 04:03:04 +08:00
|
|
|
self._create_test_db_pre_migrate_sql()
|
|
|
|
|
2014-06-09 10:30:15 +08:00
|
|
|
# We report migrate messages at one level lower than that requested.
|
2010-08-07 14:58:14 +08:00
|
|
|
# This ensures we don't get flooded with messages during testing
|
2014-06-09 10:30:15 +08:00
|
|
|
# (unless you really ask to be flooded).
|
|
|
|
call_command(
|
|
|
|
'migrate',
|
2011-01-19 00:43:01 +08:00
|
|
|
verbosity=max(verbosity - 1, 0),
|
|
|
|
interactive=False,
|
|
|
|
database=self.connection.alias,
|
2014-06-24 11:25:09 +08:00
|
|
|
test_flush=True,
|
2014-06-09 10:30:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
# We then serialize the current state of the database into a string
|
|
|
|
# and store it on the connection. This slightly horrific process is so people
|
|
|
|
# who are testing on databases without transactions or who are using
|
|
|
|
# a TransactionTestCase still get a clean database on every test run.
|
|
|
|
if serialize:
|
|
|
|
self.connection._test_serialized_contents = self.serialize_db_to_string()
|
|
|
|
|
2013-01-06 06:43:01 +08:00
|
|
|
call_command('createcachetable', database=self.connection.alias)
|
2008-08-11 20:11:25 +08:00
|
|
|
|
2014-01-09 23:05:15 +08:00
|
|
|
# Ensure a connection for the side effect of initializing the test database.
|
|
|
|
self.connection.ensure_connection()
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
return test_database_name
|
|
|
|
|
2014-06-10 04:03:04 +08:00
|
|
|
def _create_test_db_pre_migrate_sql(self):
|
|
|
|
"""
|
|
|
|
Hook for databases to load SQL before creating the test DB.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2014-06-09 10:30:15 +08:00
|
|
|
def serialize_db_to_string(self):
|
|
|
|
"""
|
|
|
|
Serializes all data in the database into a JSON string.
|
|
|
|
Designed only for test runner usage; will not handle large
|
|
|
|
amounts of data.
|
|
|
|
"""
|
|
|
|
# Build list of all apps to serialize
|
|
|
|
from django.db.migrations.loader import MigrationLoader
|
|
|
|
loader = MigrationLoader(self.connection)
|
|
|
|
app_list = []
|
|
|
|
for app_config in apps.get_app_configs():
|
|
|
|
if (
|
|
|
|
app_config.models_module is not None and
|
|
|
|
app_config.label in loader.migrated_apps and
|
|
|
|
app_config.name not in settings.TEST_NON_SERIALIZED_APPS
|
|
|
|
):
|
|
|
|
app_list.append((app_config, None))
|
2014-06-09 23:12:28 +08:00
|
|
|
|
2014-06-09 10:30:15 +08:00
|
|
|
# Make a function to iteratively return every object
|
|
|
|
def get_objects():
|
2014-10-15 23:37:23 +08:00
|
|
|
for model in serializers.sort_dependencies(app_list):
|
2014-09-04 20:15:09 +08:00
|
|
|
if (not model._meta.proxy and model._meta.managed and
|
|
|
|
router.allow_migrate(self.connection.alias, model)):
|
2014-06-09 10:30:15 +08:00
|
|
|
queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
|
|
|
|
for obj in queryset.iterator():
|
|
|
|
yield obj
|
|
|
|
# Serialise to a string
|
|
|
|
out = StringIO()
|
|
|
|
serializers.serialize("json", get_objects(), indent=None, stream=out)
|
|
|
|
return out.getvalue()
|
|
|
|
|
|
|
|
def deserialize_db_from_string(self, data):
|
|
|
|
"""
|
|
|
|
Reloads the database with data from a string generated by
|
|
|
|
the serialize_db_to_string method.
|
|
|
|
"""
|
|
|
|
data = StringIO(data)
|
|
|
|
for obj in serializers.deserialize("json", data, using=self.connection.alias):
|
|
|
|
obj.save()
|
|
|
|
|
2010-12-09 07:48:28 +08:00
|
|
|
def _get_test_db_name(self):
|
|
|
|
"""
|
2010-12-21 09:36:09 +08:00
|
|
|
Internal implementation - returns the name of the test DB that will be
|
2010-12-09 07:48:28 +08:00
|
|
|
created. Only useful when called from create_test_db() and
|
|
|
|
_create_test_db() and when no external munging is done with the 'NAME'
|
|
|
|
or 'TEST_NAME' settings.
|
|
|
|
"""
|
2014-01-20 08:45:29 +08:00
|
|
|
if self.connection.settings_dict['TEST']['NAME']:
|
|
|
|
return self.connection.settings_dict['TEST']['NAME']
|
2010-12-09 07:48:28 +08:00
|
|
|
return TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
|
|
|
|
|
2014-05-28 05:13:08 +08:00
|
|
|
def _create_test_db(self, verbosity, autoclobber, keepdb=False):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Internal implementation - creates the test db tables.
|
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
suffix = self.sql_table_creation_suffix()
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2010-12-09 07:48:28 +08:00
|
|
|
test_database_name = self._get_test_db_name()
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
|
2013-03-06 03:40:57 +08:00
|
|
|
# Create the test database and connect to it.
|
2014-01-09 23:05:15 +08:00
|
|
|
with self._nodb_connection.cursor() as cursor:
|
|
|
|
try:
|
|
|
|
cursor.execute(
|
|
|
|
"CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
|
|
|
|
except Exception as e:
|
2014-05-28 05:13:08 +08:00
|
|
|
# if we want to keep the db, then no need to do any of the below,
|
|
|
|
# just return and skip it all.
|
|
|
|
if keepdb:
|
|
|
|
return test_database_name
|
|
|
|
|
2014-01-09 23:05:15 +08:00
|
|
|
sys.stderr.write(
|
|
|
|
"Got an error creating the test database: %s\n" % e)
|
|
|
|
if not autoclobber:
|
|
|
|
confirm = input(
|
|
|
|
"Type 'yes' if you would like to try deleting the test "
|
|
|
|
"database '%s', or 'no' to cancel: " % test_database_name)
|
|
|
|
if autoclobber or confirm == 'yes':
|
|
|
|
try:
|
|
|
|
if verbosity >= 1:
|
|
|
|
print("Destroying old test database '%s'..."
|
|
|
|
% self.connection.alias)
|
|
|
|
cursor.execute(
|
|
|
|
"DROP DATABASE %s" % qn(test_database_name))
|
|
|
|
cursor.execute(
|
|
|
|
"CREATE DATABASE %s %s" % (qn(test_database_name),
|
|
|
|
suffix))
|
|
|
|
except Exception as e:
|
|
|
|
sys.stderr.write(
|
|
|
|
"Got an error recreating the test database: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
else:
|
|
|
|
print("Tests cancelled.")
|
|
|
|
sys.exit(1)
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
return test_database_name
|
2009-03-01 16:13:38 +08:00
|
|
|
|
2014-06-06 05:42:08 +08:00
|
|
|
def destroy_test_db(self, old_database_name, verbosity=1, keepdb=False):
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
|
|
|
Destroy a test database, prompting the user for confirmation if the
|
2012-02-29 05:23:45 +08:00
|
|
|
database already exists.
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
|
|
|
self.connection.close()
|
2009-12-22 23:18:51 +08:00
|
|
|
test_database_name = self.connection.settings_dict['NAME']
|
2010-11-22 01:18:26 +08:00
|
|
|
if verbosity >= 1:
|
|
|
|
test_db_repr = ''
|
2014-06-06 05:42:08 +08:00
|
|
|
action = 'Destroying'
|
2010-11-22 01:18:26 +08:00
|
|
|
if verbosity >= 2:
|
|
|
|
test_db_repr = " ('%s')" % test_database_name
|
2014-06-06 05:42:08 +08:00
|
|
|
if keepdb:
|
|
|
|
action = 'Preserving'
|
|
|
|
print("%s test database for alias '%s'%s..." % (
|
|
|
|
action, self.connection.alias, test_db_repr))
|
2012-01-30 16:27:50 +08:00
|
|
|
|
2014-06-06 05:42:08 +08:00
|
|
|
# if we want to preserve the database
|
|
|
|
# skip the actual destroying piece.
|
|
|
|
if not keepdb:
|
|
|
|
self._destroy_test_db(test_database_name, verbosity)
|
2008-08-13 00:06:55 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def _destroy_test_db(self, test_database_name, verbosity):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
Internal implementation - remove the test db tables.
|
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
# Remove the test database to clean up after
|
|
|
|
# ourselves. Connect to the previous database (not the test database)
|
|
|
|
# to do so, because it's not allowed to delete a database while being
|
|
|
|
# connected to it.
|
2014-01-09 23:05:15 +08:00
|
|
|
with self._nodb_connection.cursor() as cursor:
|
|
|
|
# Wait to avoid "database is being accessed by other users" errors.
|
|
|
|
time.sleep(1)
|
|
|
|
cursor.execute("DROP DATABASE %s"
|
|
|
|
% self.connection.ops.quote_name(test_database_name))
|
2008-08-11 20:11:25 +08:00
|
|
|
|
|
|
|
def sql_table_creation_suffix(self):
|
2012-01-30 16:27:50 +08:00
|
|
|
"""
|
|
|
|
SQL to append to the end of the test table creation statements.
|
|
|
|
"""
|
2008-08-11 20:11:25 +08:00
|
|
|
return ''
|
2011-02-02 22:02:14 +08:00
|
|
|
|
|
|
|
def test_db_signature(self):
|
|
|
|
"""
|
|
|
|
Returns a tuple with elements of self.connection.settings_dict (a
|
|
|
|
DATABASES setting value) that uniquely identify a database
|
|
|
|
accordingly to the RDBMS particularities.
|
|
|
|
"""
|
|
|
|
settings_dict = self.connection.settings_dict
|
|
|
|
return (
|
|
|
|
settings_dict['HOST'],
|
|
|
|
settings_dict['PORT'],
|
|
|
|
settings_dict['ENGINE'],
|
|
|
|
settings_dict['NAME']
|
|
|
|
)
|