MusicBrainz schema as an ER graph

Present

2-min readUpdated 6 days agomain

Copied Raw Markdown!
Copied copy path!

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.

19 Nodes and 79 Edges

How to read itURL copied

  • An area edge means "tables in this area reference tables in that area". Its foreign_keys attribute 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 NULL key gives one at the referenced end, and a nullable key gives zero_one.
  • A dashed edge is non-identifying. A solid edge is identifying, because the foreign key is part of the primary key.
  • A grey External table lives in another area. Its internals open that area.
  • A pale ExternalArea node 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 generatedURL 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.