Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support self-referencing FKs in Table.create #537

Merged
merged 1 commit into from
May 8, 2023

Conversation

numist
Copy link
Contributor

@numist numist commented Apr 12, 2023

@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (c0251cc) 96.25% compared to head (a75abeb) 96.25%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #537   +/-   ##
=======================================
  Coverage   96.25%   96.25%           
=======================================
  Files           6        6           
  Lines        2671     2673    +2     
=======================================
+ Hits         2571     2573    +2     
  Misses        100      100           
Impacted Files Coverage Δ
sqlite_utils/db.py 97.33% <100.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@numist numist changed the title Support self-referencing FKs in create Support self-referencing FKs in Table.create Apr 13, 2023
@simonw simonw merged commit 39ef137 into simonw:main May 8, 2023
@simonw
Copy link
Owner

simonw commented May 8, 2023

Thanks!

simonw added a commit that referenced this pull request May 8, 2023
simonw added a commit that referenced this pull request May 8, 2023
@simonw
Copy link
Owner

simonw commented May 8, 2023

Here's an example from the new tests:

def test_self_referential_foreign_key(fresh_db):
assert [] == fresh_db.table_names()
table = fresh_db.create_table(
"test_table",
columns={
"id": int,
"ref": int,
},
pk="id",
foreign_keys=(("ref", "test_table", "id"),),
)
assert (
"CREATE TABLE [test_table] (\n"
" [id] INTEGER PRIMARY KEY,\n"
" [ref] INTEGER REFERENCES [test_table]([id])\n"
")"
) == table.schema

@simonw simonw added the enhancement New feature or request label May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants