spacepaste

  1.  
  2. DROP DATABASE kodi_music60;
  3. CREATE DATABASE kodi_music60
  4. DEFAULT CHARACTER SET utf8
  5. DEFAULT COLLATE utf8_general_ci;
  6. USE kodi_music60;
  7. CREATE TABLE artist ( idArtist integer primary key,
  8. strArtist varchar(256), strMusicBrainzArtistID text,
  9. strBorn text, strFormed text, strGenres text, strMoods text,
  10. strStyles text, strInstruments text, strBiography text,
  11. strDied text, strDisbanded text, strYearsActive text,
  12. strImage text, strFanart text,
  13. lastScraped varchar(20) default NULL);
  14. INSERT INTO artist (idArtist, strArtist, strMusicBrainzArtistID) VALUES( 1, '[Missing Tag]', 'Artist Tag Missing' );
  15. CREATE TABLE album (idAlbum integer primary key,
  16. strAlbum varchar(256), strMusicBrainzAlbumID text,
  17. strArtists text, strGenres text,
  18. iYear integer, idThumb integer,
  19. bCompilation integer not null default '0',
  20. strMoods text, strStyles text, strThemes text,
  21. strReview text, strImage text, strLabel text,
  22. strType text,
  23. fRating FLOAT NOT NULL DEFAULT 0,
  24. iUserrating INTEGER NOT NULL DEFAULT 0,
  25. lastScraped varchar(20) default NULL,
  26. strReleaseType text,
  27. iVotes INTEGER NOT NULL DEFAULT 0);
  28. CREATE TABLE album_artist (idArtist integer, idAlbum integer, iOrder integer, strArtist text);
  29. CREATE TABLE album_genre (idGenre integer, idAlbum integer, iOrder integer);
  30. CREATE TABLE genre (idGenre integer primary key, strGenre varchar(256));
  31. CREATE TABLE path (idPath integer primary key, strPath varchar(512), strHash text);
  32. CREATE TABLE song (idSong integer primary key,
  33. idAlbum integer, idPath integer,
  34. strArtists text, strGenres text, strTitle varchar(512),
  35. iTrack integer, iDuration integer, iYear integer,
  36. dwFileNameCRC text,
  37. strFileName text, strMusicBrainzTrackID text,
  38. iTimesPlayed integer, iStartOffset integer, iEndOffset integer,
  39. idThumb integer,
  40. lastplayed varchar(20) default NULL,
  41. rating FLOAT NOT NULL DEFAULT 0, userrating INTEGER NOT NULL DEFAULT 0,
  42. comment text, mood text, dateAdded text, votes INTEGER NOT NULL DEFAULT 0);
  43. CREATE TABLE song_artist (idArtist integer, idSong integer, idRole integer, iOrder integer, strArtist text);
  44. CREATE TABLE song_genre (idGenre integer, idSong integer, iOrder integer);
  45. CREATE TABLE role (idRole integer primary key, strRole text);
  46. INSERT INTO role(idRole, strRole) VALUES (1, 'Artist');
  47. CREATE TABLE albuminfosong (idAlbumInfoSong integer primary key, idAlbumInfo integer, iTrack integer, strTitle text, iDuration integer);
  48. CREATE TABLE content (strPath text, strScraperPath text, strContent text, strSettings text);
  49. CREATE TABLE discography (idArtist integer, strAlbum text, strYear text);
  50. CREATE TABLE art(art_id INTEGER PRIMARY KEY, media_id INTEGER, media_type TEXT, type TEXT, url TEXT);
  51. CREATE TABLE cue (idPath integer, strFileName text, strCuesheet text);
  52. CREATE INDEX idxAlbum ON album(strAlbum(255));
  53. CREATE INDEX idxAlbum_1 ON album(bCompilation);
  54. CREATE UNIQUE INDEX idxAlbum_2 ON album(strMusicBrainzAlbumID(36));
  55. CREATE UNIQUE INDEX idxAlbumArtist_1 ON album_artist ( idAlbum, idArtist );
  56. CREATE UNIQUE INDEX idxAlbumArtist_2 ON album_artist ( idArtist, idAlbum );
  57. CREATE UNIQUE INDEX idxAlbumGenre_1 ON album_genre ( idAlbum, idGenre );
  58. CREATE UNIQUE INDEX idxAlbumGenre_2 ON album_genre ( idGenre, idAlbum );
  59. CREATE INDEX idxGenre ON genre(strGenre(255));
  60. CREATE INDEX idxArtist ON artist(strArtist(255));
  61. CREATE UNIQUE INDEX idxArtist1 ON artist(strMusicBrainzArtistID(36));
  62. CREATE INDEX idxPath ON path(strPath(255));
  63. CREATE INDEX idxSong ON song(strTitle(255));
  64. CREATE INDEX idxSong1 ON song(iTimesPlayed);
  65. CREATE INDEX idxSong2 ON song(lastplayed);
  66. CREATE INDEX idxSong3 ON song(idAlbum);
  67. CREATE INDEX idxSong6 ON song( idPath, strFileName(255) );
  68. CREATE UNIQUE INDEX idxSong7 ON song( idAlbum, strMusicBrainzTrackID(36) );
  69. CREATE UNIQUE INDEX idxSongArtist_1 ON song_artist ( idSong, idArtist, idRole );
  70. CREATE INDEX idxSongArtist_2 ON song_artist ( idSong, idRole );
  71. CREATE INDEX idxSongArtist_3 ON song_artist ( idArtist, idRole );
  72. CREATE INDEX idxSongArtist_4 ON song_artist ( idRole );
  73. CREATE UNIQUE INDEX idxSongGenre_1 ON song_genre ( idSong, idGenre );
  74. CREATE UNIQUE INDEX idxSongGenre_2 ON song_genre ( idGenre, idSong );
  75. CREATE INDEX idxRole on role(strRole(255));
  76. CREATE INDEX idxAlbumInfoSong_1 ON albuminfosong ( idAlbumInfo );
  77. CREATE INDEX idxDiscography_1 ON discography ( idArtist );
  78. CREATE INDEX ix_art ON art(media_id, media_type(20), type(20));
  79. CREATE UNIQUE INDEX idxCue ON cue(idPath, strFileName(255));
  80. CREATE TRIGGER tgrDeleteAlbum AFTER delete ON album FOR EACH ROW BEGIN
  81. DELETE FROM song WHERE song.idAlbum = old.idAlbum;
  82. DELETE FROM album_artist WHERE album_artist.idAlbum = old.idAlbum;
  83. DELETE FROM album_genre WHERE album_genre.idAlbum = old.idAlbum;
  84. DELETE FROM albuminfosong WHERE albuminfosong.idAlbumInfo=old.idAlbum;
  85. DELETE FROM art WHERE media_id=old.idAlbum AND media_type='album';
  86. END
  87. CREATE TRIGGER tgrDeleteArtist AFTER delete ON artist FOR EACH ROW BEGIN
  88. DELETE FROM album_artist WHERE album_artist.idArtist = old.idArtist;
  89. DELETE FROM song_artist WHERE song_artist.idArtist = old.idArtist;
  90. DELETE FROM discography WHERE discography.idArtist = old.idArtist;
  91. DELETE FROM art WHERE media_id=old.idArtist AND media_type='artist';
  92. END
  93. CREATE TRIGGER tgrDeleteSong AFTER delete ON song FOR EACH ROW BEGIN
  94. DELETE FROM song_artist WHERE song_artist.idSong = old.idSong;
  95. DELETE FROM song_genre WHERE song_genre.idSong = old.idSong;
  96. DELETE FROM art WHERE media_id=old.idSong AND media_type='song';
  97. END
  98. CREATE TRIGGER tgrDeletePath AFTER delete ON path FOR EACH ROW BEGIN
  99. DELETE FROM cue WHERE cue.idPath = old.idPath;
  100. END
  101. CREATE VIEW songview AS SELECT
  102. song.idSong AS idSong,
  103. song.strArtists AS strArtists,
  104. song.strGenres AS strGenres,
  105. strTitle,
  106. iTrack, iDuration,
  107. song.iYear AS iYear,
  108. strFileName,
  109. strMusicBrainzTrackID,
  110. iTimesPlayed, iStartOffset, iEndOffset,
  111. lastplayed,
  112. song.rating,
  113. song.userrating,
  114. song.votes,
  115. comment,
  116. song.idAlbum AS idAlbum,
  117. strAlbum,
  118. strPath,
  119. album.bCompilation AS bCompilation,
  120. album.strArtists AS strAlbumArtists,
  121. album.strReleaseType AS strAlbumReleaseType,
  122. song.mood as mood,
  123. song.dateAdded as dateAdded
  124. FROM song
  125. JOIN album ON
  126. song.idAlbum=album.idAlbum
  127. JOIN path ON
  128. song.idPath=path.idPath
  129. CREATE VIEW albumview AS SELECT
  130. album.idAlbum AS idAlbum,
  131. strAlbum,
  132. strMusicBrainzAlbumID,
  133. album.strArtists AS strArtists,
  134. album.strGenres AS strGenres,
  135. album.iYear AS iYear,
  136. album.strMoods AS strMoods,
  137. album.strStyles AS strStyles,
  138. strThemes,
  139. strReview,
  140. strLabel,
  141. strType,
  142. album.strImage as strImage,
  143. album.fRating,
  144. album.iUserrating,
  145. album.iVotes,
  146. bCompilation,
  147. (SELECT AVG(song.iTimesPlayed) FROM song WHERE song.idAlbum = album.idAlbum) AS iTimesPlayed,
  148. strReleaseType,
  149. (SELECT MAX(song.dateAdded) FROM song WHERE song.idAlbum = album.idAlbum) AS dateAdded,
  150. (SELECT MAX(song.lastplayed) FROM song WHERE song.idAlbum = album.idAlbum) AS lastplayed
  151. FROM album
  152. CREATE VIEW artistview AS SELECT
  153. idArtist, strArtist,
  154. strMusicBrainzArtistID,
  155. strBorn, strFormed, strGenres,
  156. strMoods, strStyles, strInstruments,
  157. strBiography, strDied, strDisbanded,
  158. strYearsActive, strImage, strFanart,
  159. (SELECT MAX(song.dateAdded) FROM song_artist INNER JOIN song ON song.idSong = song_artist.idSong
  160. WHERE song_artist.idArtist = artist.idArtist) AS dateAdded
  161. FROM artist
  162. CREATE VIEW albumartistview AS SELECT
  163. album_artist.idAlbum AS idAlbum,
  164. album_artist.idArtist AS idArtist,
  165. 0 AS idRole,
  166. 'AlbumArtist' AS strRole,
  167. artist.strArtist AS strArtist,
  168. artist.strMusicBrainzArtistID AS strMusicBrainzArtistID,
  169. album_artist.iOrder AS iOrder
  170. FROM album_artist
  171. JOIN artist ON
  172. album_artist.idArtist = artist.idArtist
  173. CREATE VIEW songartistview AS SELECT
  174. song_artist.idSong AS idSong,
  175. song_artist.idArtist AS idArtist,
  176. song_artist.idRole AS idRole,
  177. role.strRole AS strRole,
  178. artist.strArtist AS strArtist,
  179. artist.strMusicBrainzArtistID AS strMusicBrainzArtistID,
  180. song_artist.iOrder AS iOrder
  181. FROM song_artist
  182. JOIN artist ON
  183. song_artist.idArtist = artist.idArtist
  184. JOIN role ON
  185. song_artist.idRole = role.idRole
  186.