1 /* IMPORTANT - \n\n *MUST* separate commands */
2 CREATE TABLE `Albums` (
3 `ID` INTEGER PRIMARY KEY,
4 `Artist` INTEGER NOT NULL,
6 `SortKey` TEXT NOT NULL
9 CREATE TABLE `Artists` (
10 `ID` INTEGER PRIMARY KEY,
12 `RomanisedName` TEXT NOT NULL,
13 `SortKey` TEXT NOT NULL
16 CREATE TABLE `Tracks` (
17 `ID` INTEGER PRIMARY KEY,
18 `FileName` TEXT NOT NULL,
19 `Album` INTEGER NOT NULL,
20 `Artist` INTEGER NOT NULL,
22 `TrackNumber` INT NOT NULL,
23 `AlbumRG` FLOAT NOT NULL,
24 `SearchKey` TEXT NOT NULL,
25 `TrackRG` FLOAT NOT NULL,
26 `MusicBrainzTrackID` CHAR(36) NOT NULL
29 CREATE TABLE `LastFMCache` (
30 `TimeStamp`INT NOT NULL,
31 `Length` INT NOT NULL,
32 `Artist` TEXT NOT NULL,
33 `Album` TEXT NOT NULL,
35 `TrackNumber` INT NOT NULL,
39 CREATE TABLE `Playlists` (
40 `ID` INTEGER PRIMARY KEY,
42 `CurrentTrack` INTEGER NOT NULL
45 CREATE TABLE `PlaylistTracks` (
46 `ID` INTEGER PRIMARY KEY,
47 `Playlist` INTEGER NOT NULL,
48 `FileName` TEXT NOT NULL
51 CREATE VIEW TrackData AS
54 Tracks.FileName AS FileName,
56 AlbumArtist.Name AS AlbumArtist,
57 AlbumArtist.RomanisedName AS AlbumArtistRomanised,
58 TrackArtist.Name AS Artist,
59 TrackArtist.RomanisedName AS ArtistRomanised,
61 Tracks.TrackNumber AS TrackNumber,
62 Tracks.AlbumRG AS AlbumRG,
63 Tracks.TrackRG AS TrackRG,
64 Tracks.MusicBrainzTrackID AS MBID,
65 Tracks.SearchKey AS SearchKey
68 JOIN Albums ON Albums.ID = Tracks.Album
69 JOIN Artists AS TrackArtist ON Tracks.Artist = TrackArtist.ID
70 JOIN Artists AS AlbumArtist ON Albums.Artist = AlbumArtist.ID;
72 /* For MySQL - SQLite Will Barf */
73 ALTER TABLE `Albums` ADD KEY(`Artist`);
75 ALTER TABLE `Albums` CHANGE COLUMN `ID` `ID` INTEGER AUTO_INCREMENT;
77 ALTER TABLE `Albums` CONVERT TO CHARACTER SET UTF8;
79 ALTER TABLE `Artists` CHANGE COLUMN `ID` `ID` INTEGER AUTO_INCREMENT;
81 ALTER TABLE `Artists` CONVERT TO CHARACTER SET UTF8;
83 ALTER TABLE `Playlists` CHANGE COLUMN `ID` `ID` INTEGER AUTO_INCREMENT;
85 ALTER TABLE `Playlists` CONVERT TO CHARACTER SET UTF8;
87 ALTER TABLE `PlaylistTracks` CHANGE COLUMN `ID` `ID` INTEGER AUTO_INCREMENT;
89 ALTER TABLE `PlaylistTracks` CONVERT TO CHARACTER SET UTF8;
91 ALTER TABLE `Tracks` CHANGE COLUMN `ID` `ID` INTEGER AUTO_INCREMENT;
93 ALTER TABLE `Tracks` CONVERT TO CHARACTER SET UTF8;
95 ALTER TABLE `Tracks` ADD KEY(`Artist`);
97 ALTER TABLE `Tracks` ADD KEY(`Album`);