[ACCEPTED]-Schema for music lists + playlists web app-schema

Accepted answer
Score: 21

You haven't given a lot of details so I'm 33 answering as best I can. I think a relational 32 database solution is perfect for this problem 31 and though you might end up with millions 30 of records in the playlists and playlists_songs tables any modern 29 RDBMS should be able to handle that with 28 no problems.

You may or may not need/want 27 a table for albums, I've included it here for 26 the sake of completeness...

albums
    id          unsigned int(P)
    artist_id   unsigned int(F artists.id)
    name        varchar(50)
    ...

+----+-----------+-----------------------------------+-----+
| id | artist_id | name                              | ... |
+----+-----------+-----------------------------------+-----+
|  1 |         1 | The Last in Line                  | ... |
|  2 |         3 | American IV: The Man Comes Around | ... |
|  3 |         2 | Animal House Soundtrack           | ... |
|  4 |         4 | None or Unknown                   | ... |
| .. | ......... | ................................. | ... |
+----+-----------+-----------------------------------+-----+

Like albums, you 25 may or may not want a table for artists but I've 24 included it in case you want to show that 23 kind of data.

artists
    id              unsigned int(P)
    name            varchar(50)
    ...

+----+-------------+
| id | name        |
+----+-------------+
|  1 | Dio         |
|  2 | Various     |
|  3 | Johnny Cash |
|  4 | Unknown     |
|  5 | Sam Cooke   |
| .. | ........... |
+----+-------------+

I view playlists as very basic: a user 22 can have an unlimited number of them and 21 they have a name. In my example data we 20 see that bob has two playlists "Mix" and 19 "Speeches" while mary has only one "Oldies".

playlists
    id          unsigned int(P)
    user_id     unsigned int(F users.id)
    name        varchar(50)

+----+---------+----------+
| id | user_id | name     |
+----+---------+----------+
|  1 |       1 | Mix      |
|  2 |       1 | Speeches |
|  3 |       2 | Oldies   |
| .. | ....... | ........ |
+----+---------+----------+

We 18 have to keep track of what songs are on 17 each playlist. In my example data you can 16 see that "Egypt (The Chains Are On)" and 15 "Hurt" are on the "Mix" playlist while the 14 "Town Hall speech" is on the "Speeches" playlist 13 and "Egypt (The Chains Are On)", "Hurt" and 12 "Twistin' the Night Away" are all on the 11 "Oldies" playlist.

playlists_songs
    id              unsigned int(P)
    playlist_id     unsigned int(F playlists.id)
    song_id         unsigned int(F songs.id)

+----+-------------+---------+
| id | playlist_id | song_id |
+----+-------------+---------+
|  1 |           1 |       1 |
|  2 |           1 |       2 |
|  3 |           2 |       4 |
|  4 |           3 |       1 |
|  5 |           3 |       2 |
|  6 |           3 |       3 |
| .. | ........... | ....... |
+----+-------------+---------+

Even though millions of 10 users might all have the song "Hurt" in 9 their collection, we only need to store 8 information about each song once. So in 7 the songs table we store information about each 6 song including where the actual audio file 5 is located. My example for file locations 4 are just off the top of my head, how you 3 would actually organize the files in the 2 filesystem could easily be very different.

songs
    id              unsigned int(P)
    album_id        unsigned int(F albums.id) // Default NULL
    artist_id       unsigned int(F artists.id)
    name            varchar(50)
    filename        varchar(255)
    ...

+----+----------+-----------+---------------------------+---------------------------+-----+
| id | album_id | artist_id | name                      | filename                  | ... |
+----+----------+-----------+---------------------------+---------------------------+-----+
|  1 |        1 |         1 | Egypt (The Chains Are On) | /media/audio/1/1/9.mp3    | ... |
|  2 |        2 |         3 | Hurt                      | /media/audio/3/2/2.mp3    | ... |
|  3 |        3 |         5 | Twistin' the Night Away   | /media/audio/5/2/3.mp3    | ... |
|  4 |     NULL |         4 | Town Hall speech          | /media/audio/4/4/<id>.mp3 | ... |
| .. | ........ | ......... | ......................... | ......................... | ... |
+----+----------+-----------+---------------------------+---------------------------+-----+

And 1 of course your users table.

users
    id              unsigned int(P)
    username        varchar(32)
    password        varbinary(255)
    ...

+----+----------+----------+-----+
| id | username | password | ... |
+----+----------+----------+-----+
|  1 | bob      | ******** | ... |
|  2 | mary     | ******** | ... |
| .. | ........ | ........ | ... |
+----+----------+----------+-----+
Score: 2

I think having a conceptual design like 8 below will helps. enter image description here The key here is to store 7 media files out of application's database 6 and make a link between them by media's 5 path. Some RDBMS's provide APIs to access 4 file system, like Oracle BFILE or SqlServer FILESTREAM .

Using relational 3 or No-Sql solution is related to application 2 business.
Any of them come with its own 1 pros and cons, a comparison could be found here.

More Related questions