Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/_utils/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,22 @@ CREATE TABLE `bulk_create_relatedmodel_bigautofieldmodel` (
KEY (`relatedmodel_id`),
KEY (`bigautofieldmodel_id`)
);

-- backends
CREATE TABLE `backends_verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_person` (
`verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id` BIGINT NOT NULL,
`person_id` BIGINT NOT NULL,
SHARD KEY (`verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id`),
UNIQUE KEY (`verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id`, `person_id`),
KEY (`verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id`),
KEY (`person_id`)
);

CREATE TABLE `backends_object_object` (
`from_object_id` BIGINT NOT NULL,
`to_object_id` BIGINT NOT NULL,
SHARD KEY (`from_object_id`),
UNIQUE KEY (`from_object_id`, `to_object_id`),
KEY (`from_object_id`),
KEY (`to_object_id`)
);
35 changes: 28 additions & 7 deletions tests/backends/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(models.Model):
max_length=100
)
m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = (
models.ManyToManyField(Person, blank=True)
models.ManyToManyField(Person, blank=True,
through="VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZPerson")
)


class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZPerson(models.Model):
verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ForeignKey(
VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ, on_delete=models.CASCADE
)
person = models.ForeignKey(Person, on_delete=models.CASCADE)

class Meta:
unique_together = (('verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', 'person'),)
db_table = "backends_verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_person"


class Tag(models.Model):
name = models.CharField(max_length=30)
content_type = models.ForeignKey(
Expand Down Expand Up @@ -102,14 +114,23 @@ def __str__(self):

class Object(models.Model):
related_objects = models.ManyToManyField(
"self", db_constraint=False, symmetrical=False
)
"self", symmetrical=False, through="ObjectFriend"
)
obj_ref = models.ForeignKey("ObjectReference", models.CASCADE, null=True)

def __str__(self):
return str(self.id)


class ObjectFriend(models.Model):
from_object = models.ForeignKey(Object, on_delete=models.CASCADE, related_name="from_object")
to_object = models.ForeignKey(Object, on_delete=models.CASCADE, related_name="to_object")

class Meta:
unique_together = (('from_object', 'to_object'),)
db_table = "backends_object_object"


class ObjectReference(models.Model):
obj = models.ForeignKey(Object, models.CASCADE, db_constraint=False)

Expand All @@ -118,20 +139,20 @@ def __str__(self):


class ObjectSelfReference(models.Model):
key = models.CharField(max_length=3, unique=True)
key = models.CharField(max_length=3, primary_key=True)
obj = models.ForeignKey("ObjectSelfReference", models.SET_NULL, null=True)


class CircularA(models.Model):
key = models.CharField(max_length=3, unique=True)
key = models.CharField(max_length=3, primary_key=True)
obj = models.ForeignKey("CircularB", models.SET_NULL, null=True)

def natural_key(self):
return (self.key,)


class CircularB(models.Model):
key = models.CharField(max_length=3, unique=True)
key = models.CharField(max_length=3, primary_key=True)
obj = models.ForeignKey("CircularA", models.SET_NULL, null=True)

def natural_key(self):
Expand All @@ -143,7 +164,7 @@ class RawData(models.Model):


class Author(models.Model):
name = models.CharField(max_length=255, unique=True)
name = models.CharField(max_length=255, primary_key=True)


class Book(models.Model):
Expand Down
7 changes: 7 additions & 0 deletions tests/backends/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from decimal import Decimal, Rounded

from django.db import NotSupportedError, connection
from django.db.utils import OperationalError
from django.db.backends.utils import (
format_number,
split_identifier,
Expand Down Expand Up @@ -94,6 +95,12 @@ class CursorWrapperTests(TransactionTestCase):
available_apps = []

def _test_procedure(self, procedure_sql, params, param_types, kparams=None):
# make sure procedure is not already defined
try:
with connection.schema_editor() as editor:
editor.remove_procedure("test_procedure", param_types)
except OperationalError:
pass
with connection.cursor() as cursor:
cursor.execute(procedure_sql)
# Use a new cursor because in MySQL a procedure can't be used in the
Expand Down
Loading