1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[multi-db] Updated tests/othertests/manager_schema_manipulation to use OTHER_DATABASES settings and access db connection through model._default_manager.db.

git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3378 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jason Pellerin 2006-07-19 14:39:18 +00:00
parent b8d27f0bcf
commit f350bcf058

View File

@ -1,8 +1,15 @@
""" """
# Django uses a model's default manager to perform schema manipulations such as # Django uses a model's default manager to perform schema
# creating or dropping the model's table. # manipulations such as creating or dropping the model's table.
>>> from django.db import models >>> from django.db import models
>>> from django.conf import settings
>>> import copy
# save copy of settings so we can restore it later
>>> odb = copy.deepcopy(settings.OTHER_DATABASES)
>>> settings.OTHER_DATABASES['django_test_db_a']['MODELS'] = [ 'msm.PA', 'msm.P', 'msm.PC' ]
>>> settings.OTHER_DATABASES['django_test_db_b']['MODELS'] = [ 'msm.QA', 'msm.QB', 'msm.QC', 'msm.QD' ]
# default connection # default connection
>>> class DA(models.Model): >>> class DA(models.Model):
@ -21,7 +28,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_a' ... app_label = 'msm'
>>> class PB(models.Model): >>> class PB(models.Model):
... name = models.CharField(maxlength=20) ... name = models.CharField(maxlength=20)
@ -31,7 +38,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_a' ... app_label = 'msm'
>>> class PC(models.Model): >>> class PC(models.Model):
... name = models.CharField(maxlength=20) ... name = models.CharField(maxlength=20)
@ -41,7 +48,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_a' ... app_label = 'msm'
# connection django_test_db_b # connection django_test_db_b
>>> class QA(models.Model): >>> class QA(models.Model):
@ -51,7 +58,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_b' ... app_label = 'msm'
>>> class QB(models.Model): >>> class QB(models.Model):
... name = models.CharField(maxlength=20) ... name = models.CharField(maxlength=20)
@ -61,7 +68,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_b' ... app_label = 'msm'
# many-many # many-many
>>> class QC(models.Model): >>> class QC(models.Model):
@ -71,7 +78,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_b' ... app_label = 'msm'
>>> class QD(models.Model): >>> class QD(models.Model):
... name = models.CharField(maxlength=20) ... name = models.CharField(maxlength=20)
@ -81,7 +88,7 @@
... return self.name ... return self.name
... ...
... class Meta: ... class Meta:
... db_connection = 'django_test_db_b' ... app_label = 'msm'
# Using the manager, models can be installed individually, whether they # Using the manager, models can be installed individually, whether they
# use the default connection or a named connection. # use the default connection or a named connection.
@ -112,14 +119,14 @@
# before the pending statements can be installed. # before the pending statements can be installed.
# NOTE: pretend db supports constraints for this test # NOTE: pretend db supports constraints for this test
>>> real_cnst = PA._meta.connection_info.backend.supports_constraints >>> real_cnst = PA._default_manager.db.backend.supports_constraints
>>> PA._meta.connection_info.backend.supports_constraints = True >>> PA._default_manager.db.backend.supports_constraints = True
>>> result = PA.objects.install() >>> result = PA.objects.install()
>>> result >>> result
{<class 'othertests.manager_schema_manipulation.PC'>: [BoundStatement('ALTER TABLE "othertests_pa" ADD CONSTRAINT "c_id_referencing_othertests_pc_id" FOREIGN KEY ("c_id") REFERENCES "othertests_pc" ("id");')]} {<class 'othertests.manager_schema_manipulation.PC'>: [BoundStatement('ALTER TABLE "msm_pa" ADD CONSTRAINT "c_id_referencing_msm_pc_id" FOREIGN KEY ("c_id") REFERENCES "msm_pc" ("id");')]}
# NOTE: restore real constraint flag # NOTE: restore real constraint flag
>>> PA._meta.connection_info.backend.supports_constraints = real_cnst >>> PA._default_manager.db.backend.supports_constraints = real_cnst
# Models with many-many relationships may also have pending statement # Models with many-many relationships may also have pending statement
# lists. Like other pending statements, these should be executed after # lists. Like other pending statements, these should be executed after
@ -131,4 +138,6 @@
>>> QD.objects.install() >>> QD.objects.install()
{} {}
# Finally, restore the original settings
>>> settings.OTHER_DATABASES = odb
""" """