mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-26 02:44:33 +02:00
add_foreign_key can now detect table and pk, refs #25
This commit is contained in:
parent
c2622ceabd
commit
d645032cfa
7 changed files with 100 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from sqlite_utils.db import Index
|
||||
import pytest
|
||||
|
||||
|
||||
def test_table_names(existing_db):
|
||||
|
|
@ -79,3 +80,19 @@ def test_indexes(fresh_db):
|
|||
),
|
||||
Index(seq=1, name="Gosh_c1", unique=0, origin="c", partial=0, columns=["c1"]),
|
||||
] == fresh_db["Gosh"].indexes
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"column,expected_table_guess",
|
||||
(
|
||||
("author", "authors"),
|
||||
("author_id", "authors"),
|
||||
("authors", "authors"),
|
||||
("genre", "genre"),
|
||||
("genre_id", "genre"),
|
||||
),
|
||||
)
|
||||
def test_guess_foreign_table(fresh_db, column, expected_table_guess):
|
||||
fresh_db.create_table("authors", {"name": str})
|
||||
fresh_db.create_table("genre", {"name": str})
|
||||
assert expected_table_guess == fresh_db["books"].guess_foreign_table(column)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue