-
-
Notifications
You must be signed in to change notification settings - Fork 773
Open
Labels
Description
While hacking around with https://github.com/datasette/datasette-acl I noticed this table:
Those resource_id
integers link to this table:
CREATE TABLE acl_resources (
id integer primary key autoincrement,
database text not null,
resource text,
unique(database, resource)
);
In this particular case, showing the database and then the resource as the foreign key label would make sense - both of those are strings and they are unique together, which makes them a valid label.
I poked around with Claude and came up with this query:
select
m.name as table_name,
json_group_array(ii.name) as unique_column_names
from
sqlite_master as m,
pragma_index_list(m.name) AS il,
pragma_index_info(il.name) AS ii
where
m.type = 'table'
and il.origin = 'u'
group by
il.name;
Which returns this for that schema:
This could be a useful alternative way to determine default foreign key labels.