MusicBrainz schema as an ER graph
2-min readUpdated 6 days ago
Here we see the full MusicBrainz database schema: 370 tables and 762 foreign keys. The top level shows 19 subject areas. Each area node opens its own pack of tables and columns through internals.
How to read it URL copied
- An area edge means "tables in this area reference tables in that area". Its
foreign_keysattribute gives the count. - Inside an area, each foreign key runs from its column to the key it references. The crow's-foot ends come from the DDL: a
NOT NULLkey givesoneat the referenced end, and a nullable key giveszero_one. - A dashed edge is non-identifying. A solid edge is identifying, because the foreign key is part of the primary key.
- A grey
Externaltable lives in another area. Itsinternalsopen that area. - A pale
ExternalAreanode stands for every table in another area that references this area.
The ER vocabulary is in Entity-relationship diagrams as a KG.
How it was generated URL copied
The pack is generated from the schema files in the admin/sql/ folder of metabrainz/musicbrainz-server. These are CreateTables.sql, CreatePrimaryKeys.sql, and CreateFKConstraints.sql.
vyasa sql-kg CreateTables.sql CreatePrimaryKeys.sql CreateFKConstraints.sql \
-o demo/musicbrainz-er.kg --title "MusicBrainz schema" \
--module 'link_types=^link' --module 'relationships=^l_' --module 'release_group=^release_group' \
--module 'medium=^(medium|track|cdtoc|alternative_medium|alternative_track)' \
--module 'release=^(release|alternative_release)' \
--module 'editor=^editor' --module 'editing=^(edit|vote|autoeditor)' \
--module 'classification=^(tag|genre|mood)' \
--module 'system=^(replication_control|unreferenced_row_log|dbmirror)'
Each --module NAME=REGEX rule puts the matching tables in one area. The first rule that matches wins. A table that no rule matches joins the area of its longest table-name prefix. For example, artist_alias_type joins artist. A table that is left alone in its own area joins the area it links to most.