Skip to content

Commit 9d5206a

Browse files
committed
added a test for adding a column with an index using MigrationManager
1 parent 55a5193 commit 9d5206a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/apps/migrations/auto/test_migration_manager.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,36 @@ def test_add_column(self):
146146
response = self.run_sync("SELECT * FROM manager;")
147147
self.assertEqual(response, [{"id": 1, "name": "Dave"}])
148148

149+
@postgres_only
150+
def test_add_column_with_index(self):
151+
"""
152+
Test adding a column with an index to a MigrationManager.
153+
"""
154+
manager = MigrationManager()
155+
manager.add_column(
156+
table_class_name="Manager",
157+
tablename="manager",
158+
column_name="email",
159+
column_class_name="Varchar",
160+
params={
161+
"length": 100,
162+
"default": "",
163+
"null": True,
164+
"primary": False,
165+
"key": False,
166+
"unique": True,
167+
"index": True,
168+
},
169+
)
170+
index_name = Manager._get_index_name(["email"])
171+
172+
asyncio.run(manager.run())
173+
self.assertTrue(index_name in Manager.indexes().run_sync())
174+
175+
# Reverse
176+
asyncio.run(manager.run_backwards())
177+
self.assertTrue(index_name not in Manager.indexes().run_sync())
178+
149179
@postgres_only
150180
def test_add_foreign_key_self_column(self):
151181
"""

0 commit comments

Comments
 (0)