4 ms·
Would you mind sharing your Script for parsing the db schema?
by hippee-lee 17y ago
Would you mind sharing your Script for parsing the db schema?
- thristian 17y agoI'd like to, but I wrote it on company time and hence don't actually have the right to distribute it. I will say that the trickiest bits were extracting the exact information from the database, and figuring out the how to make arrows point to and from individual fields, instead of from the table in general. Getting tables and fields from PostgreSQL: select table_schema, table_schema || '.' || table_name as qualified_table, column_name, data_type from information_schema.columns order by table_schema, table_name, ordinal_position; Getting foreign-key information from PostgreSQL: select kcu.table_schema, kcu.table_schema || '.' || kcu.table_name as qualified_table, kcu.column_name, ccu.table_schema as referenced_table_schema, ccu.table_schema || '.' || ccu.table_name as referenced_qualified_table, ccu.column_name as referenced_column_name from information_schema.constraint_column_usage as ccu join information_schema.key_column_usage as kcu using (constraint_catalog, constraint_schema, constraint_name) where ccu.table_schema != kcu.table_schema or ccu.table_name != kcu.table_name; As for the DOT output, I wound up using their HTML table support, generating a unique name for each cell in the table (port="blah" on each td element) and defining the foreign key arrows as going from table1:field1:e to table2:field2:w when table1.field1 is a foreign key referencing table2.field2.
- hippee-lee 17y agoI am using mysql. Maybe I can figure something out and post it back here ... Thanks for the hints.