Changing Data and Table Structure Together

Our new compositions table is working better now that we’ve added some indexes, but as we start adding data, we discover another problem. Our current structure only allows us to associate one composer with each record, and some songs have more than one composer. As we think about it further, we realize that many songs have separate composers and lyricists, and we might want to capture that info as well.

This sounds like a job for a many-to-many relationship between compositions and artists: a composition can have many artists, and an artist can contribute to many songs. As we discussed in Chapter 3, Connecting Your Tables to Elixir Structs with Schemas we’ll need a new join table between compositions ...

Get Programming Ecto now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.