mirror of
https://github.com/django/django.git
synced 2025-06-16 00:49:12 +00:00
[5.2.x] Refs #36052, #32234 -- Removed create_test_table_with_composite_primary_key flag in favor of using CompositePrimaryKey.
Now that Django properly supports creating models with composite primary keys, the tests should use a `CompositePrimaryKey` field instead of a feature flag to inline backend specific SQL for creating a composite PK. Specifcially, the inspectdb's test_composite_primary_key was adjusted to use schema editor instead of per-backend raw SQL. Backport of 4c75858135589f3a00e32eb4d476074536371a32 from main.
This commit is contained in:
parent
7f6a5fbe2e
commit
5d03c71b7a
@ -278,10 +278,6 @@ class BaseDatabaseFeatures:
|
|||||||
create_test_procedure_without_params_sql = None
|
create_test_procedure_without_params_sql = None
|
||||||
create_test_procedure_with_int_param_sql = None
|
create_test_procedure_with_int_param_sql = None
|
||||||
|
|
||||||
# SQL to create a table with a composite primary key for use by the Django
|
|
||||||
# test suite.
|
|
||||||
create_test_table_with_composite_primary_key = None
|
|
||||||
|
|
||||||
# Does the backend support keyword parameters for cursor.callproc()?
|
# Does the backend support keyword parameters for cursor.callproc()?
|
||||||
supports_callproc_kwargs = False
|
supports_callproc_kwargs = False
|
||||||
|
|
||||||
|
@ -41,13 +41,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
SET V_I = P_I;
|
SET V_I = P_I;
|
||||||
END;
|
END;
|
||||||
"""
|
"""
|
||||||
create_test_table_with_composite_primary_key = """
|
|
||||||
CREATE TABLE test_table_composite_pk (
|
|
||||||
column_1 INTEGER NOT NULL,
|
|
||||||
column_2 INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY(column_1, column_2)
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
# Neither MySQL nor MariaDB support partial indexes.
|
# Neither MySQL nor MariaDB support partial indexes.
|
||||||
supports_partial_indexes = False
|
supports_partial_indexes = False
|
||||||
# COLLATE must be wrapped in parentheses because MySQL treats COLLATE as an
|
# COLLATE must be wrapped in parentheses because MySQL treats COLLATE as an
|
||||||
|
@ -60,13 +60,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
V_I := P_I;
|
V_I := P_I;
|
||||||
END;
|
END;
|
||||||
"""
|
"""
|
||||||
create_test_table_with_composite_primary_key = """
|
|
||||||
CREATE TABLE test_table_composite_pk (
|
|
||||||
column_1 NUMBER(11) NOT NULL,
|
|
||||||
column_2 NUMBER(11) NOT NULL,
|
|
||||||
PRIMARY KEY (column_1, column_2)
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
supports_callproc_kwargs = True
|
supports_callproc_kwargs = True
|
||||||
supports_over_clause = True
|
supports_over_clause = True
|
||||||
supports_frame_range_fixed_distance = True
|
supports_frame_range_fixed_distance = True
|
||||||
|
@ -52,13 +52,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
V_I := P_I;
|
V_I := P_I;
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;"""
|
$$ LANGUAGE plpgsql;"""
|
||||||
create_test_table_with_composite_primary_key = """
|
|
||||||
CREATE TABLE test_table_composite_pk (
|
|
||||||
column_1 INTEGER NOT NULL,
|
|
||||||
column_2 INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY(column_1, column_2)
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
requires_casted_case_in_updates = True
|
requires_casted_case_in_updates = True
|
||||||
supports_over_clause = True
|
supports_over_clause = True
|
||||||
supports_frame_exclusion = True
|
supports_frame_exclusion = True
|
||||||
|
@ -51,13 +51,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
# Date/DateTime fields and timedeltas.
|
# Date/DateTime fields and timedeltas.
|
||||||
"expressions.tests.FTimeDeltaTests.test_mixed_comparisons1",
|
"expressions.tests.FTimeDeltaTests.test_mixed_comparisons1",
|
||||||
}
|
}
|
||||||
create_test_table_with_composite_primary_key = """
|
|
||||||
CREATE TABLE test_table_composite_pk (
|
|
||||||
column_1 INTEGER NOT NULL,
|
|
||||||
column_2 INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY(column_1, column_2)
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
insert_test_table_with_defaults = 'INSERT INTO {} ("null") VALUES (1)'
|
insert_test_table_with_defaults = 'INSERT INTO {} ("null") VALUES (1)'
|
||||||
supports_default_keyword_in_insert = False
|
supports_default_keyword_in_insert = False
|
||||||
supports_unlimited_charfield = True
|
supports_unlimited_charfield = True
|
||||||
|
@ -155,3 +155,9 @@ class DbComment(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
db_table_comment = "Custom table comment"
|
db_table_comment = "Custom table comment"
|
||||||
required_db_features = {"supports_comments"}
|
required_db_features = {"supports_comments"}
|
||||||
|
|
||||||
|
|
||||||
|
class CompositePrimaryKeyModel(models.Model):
|
||||||
|
pk = models.CompositePrimaryKey("column_1", "column_2")
|
||||||
|
column_1 = models.IntegerField()
|
||||||
|
column_2 = models.IntegerField()
|
||||||
|
@ -626,17 +626,13 @@ class InspectDBTransactionalTests(TransactionTestCase):
|
|||||||
self.assertIn(foreign_table_model, output)
|
self.assertIn(foreign_table_model, output)
|
||||||
self.assertIn(foreign_table_managed, output)
|
self.assertIn(foreign_table_managed, output)
|
||||||
|
|
||||||
@skipUnlessDBFeature("create_test_table_with_composite_primary_key")
|
|
||||||
def test_composite_primary_key(self):
|
def test_composite_primary_key(self):
|
||||||
table_name = "test_table_composite_pk"
|
|
||||||
cursor_execute(connection.features.create_test_table_with_composite_primary_key)
|
|
||||||
self.addCleanup(cursor_execute, "DROP TABLE %s" % table_name)
|
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
if connection.vendor == "sqlite":
|
if connection.vendor == "sqlite":
|
||||||
field_type = connection.features.introspected_field_types["AutoField"]
|
field_type = connection.features.introspected_field_types["AutoField"]
|
||||||
else:
|
else:
|
||||||
field_type = connection.features.introspected_field_types["IntegerField"]
|
field_type = connection.features.introspected_field_types["IntegerField"]
|
||||||
call_command("inspectdb", table_name, stdout=out)
|
call_command("inspectdb", "inspectdb_compositeprimarykeymodel", stdout=out)
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"pk = models.CompositePrimaryKey('column_1', 'column_2')",
|
"pk = models.CompositePrimaryKey('column_1', 'column_2')",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user