simonw / datasette-edit-schema

Datasette plugin for modifying table schemas
Apache License 2.0
16 stars 0 forks source link

Add and edit foreign keys #7

Closed simonw closed 1 year ago

simonw commented 4 years ago

https://sqlite-utils.readthedocs.io/en/stable/python-api.html#adding-foreign-key-constraints

simonw commented 1 year ago

I realized that I need this for Datasette Cloud, because the API and GraphQL API is much more interesting if you have foreign keys between things.

simonw commented 1 year ago

Also realized that I can suggest foreign keys (for tables smaller than a certain limit, I'll pick 10,000 for the moment) just by checking each column to see if it only contains values that exist as primary keys in another table - with a short-circuit so the moment you find a non-matching key you stop the search.

simonw commented 1 year ago

Got a prototype working. I'm going to ship that as an alpha, then add tests and docs later on.

simonw commented 1 year ago

Demo:

fk-demo