mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
ignore=True argument for add_foreign_key, closes #112
Also --ignore for add-foreign-key command Plus table.add_foreign_key(...) now returns self, allowing more chaining
This commit is contained in:
parent
ecb50c8f76
commit
e23eedb4ce
6 changed files with 48 additions and 9 deletions
|
|
@ -272,16 +272,24 @@ def test_add_foreign_key(db_path, args, assert_message):
|
|||
table="books", column="author_id", other_table="authors", other_column="id"
|
||||
)
|
||||
] == db["books"].foreign_keys
|
||||
|
||||
# Error if we try to add it twice:
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["add-foreign-key", db_path, "books", "author_id", "authors", "id"]
|
||||
)
|
||||
|
||||
assert 0 != result.exit_code
|
||||
assert (
|
||||
"Error: Foreign key already exists for author_id => authors.id"
|
||||
== result.output.strip()
|
||||
)
|
||||
|
||||
# No error if we add it twice with --ignore
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["add-foreign-key", db_path, "books", "author_id", "authors", "id", "--ignore"],
|
||||
)
|
||||
assert 0 == result.exit_code
|
||||
|
||||
# Error if we try against an invalid column
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["add-foreign-key", db_path, "books", "author_id", "authors", "bad"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue