Skip to content

Commit fe13064

Browse files
Remove unnecessary foreign key operation overrides
1 parent 2e91e8d commit fe13064

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

aurora_dsql_django/schema.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class DatabaseSchemaEditor(schema.DatabaseSchemaEditor):
4949

5050
# These "ALTER TABLE" operations are not supported.
5151
sql_create_pk = ""
52-
sql_create_fk = ""
53-
sql_delete_fk = ""
5452
sql_create_check = ""
5553
sql_delete_check = ""
5654
sql_delete_constraint = ""

aurora_dsql_django/tests/unit/test_schema.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def setUp(self):
1111
self.schema_editor = DatabaseSchemaEditor(self.connection)
1212

1313
def test_sql_attributes(self):
14-
self.assertEqual(self.schema_editor.sql_delete_fk, "")
1514
self.assertEqual(self.schema_editor.sql_create_pk, "")
1615
self.assertEqual(self.schema_editor.sql_create_index,
1716
"CREATE INDEX ASYNC %(name)s ON %(table)s%(using)s (%(columns)s)%(include)s%(extra)s%(condition)s")
@@ -24,7 +23,6 @@ def test_sql_attributes(self):
2423
self.schema_editor.sql_update_with_default,
2524
"UPDATE %(table)s SET %(column)s = %(default)s WHERE %(column)s IS NULL"
2625
)
27-
self.assertEqual(self.schema_editor.sql_create_fk, "")
2826
self.assertEqual(self.schema_editor.sql_create_check, "")
2927
self.assertEqual(self.schema_editor.sql_delete_check, "")
3028
self.assertEqual(self.schema_editor.sql_delete_constraint, "")
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import unittest
2+
from unittest.mock import MagicMock, patch
3+
import django
4+
from django.conf import settings
5+
from django.db import models
6+
from aurora_dsql_django.base import DatabaseWrapper
7+
from aurora_dsql_django.features import DatabaseFeatures
8+
from aurora_dsql_django.schema import DatabaseSchemaEditor
9+
10+
if not settings.configured:
11+
settings.configure(
12+
INSTALLED_APPS=['django.contrib.contenttypes'],
13+
DATABASES={'default': {'ENGINE': 'aurora_dsql_django'}},
14+
USE_TZ=True,
15+
)
16+
django.setup()
17+
18+
19+
class TestWrapper(unittest.TestCase):
20+
"""Test Aurora DSQL wrapper behavior when all parts are working together"""
21+
22+
def setUp(self):
23+
self.connection = DatabaseWrapper({})
24+
self.connection.connection = MagicMock()
25+
self.connection.connection.encoding = 'utf8'
26+
27+
# Configure mock to use real components.
28+
self.connection.features = DatabaseFeatures(self.connection)
29+
self.schema_editor = DatabaseSchemaEditor(self.connection)
30+
31+
def test_foreign_key_sql_generation(self):
32+
"""Ensure foreign key SQL is not generated when the feature is disabled"""
33+
34+
class ParentModel(models.Model):
35+
class Meta:
36+
app_label = 'test_app'
37+
38+
class ChildModel(models.Model):
39+
parent = models.ForeignKey(ParentModel, on_delete=models.CASCADE)
40+
41+
class Meta:
42+
app_label = 'test_app'
43+
44+
# Mock execute to capture SQL without actually running it.
45+
with patch.object(self.schema_editor, 'execute'):
46+
with self.schema_editor:
47+
self.schema_editor.create_model(ChildModel)
48+
49+
# Check that no foreign key SQL was deferred.
50+
foreign_key_statements = [sql for sql in self.schema_editor.deferred_sql if 'FOREIGN KEY' in str(sql)]
51+
self.assertListEqual([], foreign_key_statements, "Should not generate foreign key SQL")
52+
53+
54+
if __name__ == '__main__':
55+
unittest.main()

0 commit comments

Comments
 (0)