File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -475,6 +475,18 @@ def test_index_foreign_keys(fresh_db):
475
475
assert [["breed_id" ]] == [i .columns for i in fresh_db ["dogs" ].indexes ]
476
476
477
477
478
+ def test_index_foreign_keys_if_index_name_is_already_used (fresh_db ):
479
+ # https://github.com/simonw/sqlite-utils/issues/335
480
+ test_add_foreign_key_guess_table (fresh_db )
481
+ # Add index with a name that will conflict with index_foreign_keys()
482
+ fresh_db ["dogs" ].create_index (["name" ], index_name = "idx_dogs_breed_id" )
483
+ fresh_db .index_foreign_keys ()
484
+ assert {(idx .name , tuple (idx .columns )) for idx in fresh_db ["dogs" ].indexes } == {
485
+ ("idx_dogs_breed_id_2" , ("breed_id" ,)),
486
+ ("idx_dogs_breed_id" , ("name" ,)),
487
+ }
488
+
489
+
478
490
@pytest .mark .parametrize (
479
491
"extra_data,expected_new_columns" ,
480
492
[
@@ -753,9 +765,8 @@ def test_create_index_desc(fresh_db):
753
765
)
754
766
755
767
756
- def test_create_index_find_unique_name ():
757
- db = Database (memory = True )
758
- table = db ["t" ]
768
+ def test_create_index_find_unique_name (fresh_db ):
769
+ table = fresh_db ["t" ]
759
770
table .insert ({"id" : 1 })
760
771
table .create_index (["id" ])
761
772
# Without find_unique_name should error
You can’t perform that action at this time.
0 commit comments