Files
samskivert/projects/robodj/src/sql/create_repository.mysql
T
mdb a8fdad6afb Revamped preferences handling; added support for voting for songs you
like. Eventually we'll actually make use of the voting information.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1116 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2003-05-04 18:16:07 +00:00

64 lines
1.7 KiB
SQL

/**
* $Id: create_repository.mysql,v 1.2 2003/05/04 18:16:07 mdb Exp $
*
* Creates the necessary database tables in MySQL for the music repository.
*/
/**
* The entries table contains a row for every entry (album, single, etc.)
* in the repository.
*/
DROP TABLE IF EXISTS entries;
CREATE TABLE entries (
entryid INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(200) NOT NULL,
artist VARCHAR(200) NOT NULL,
source VARCHAR(20) NOT NULL
);
/**
* The songs associated with every entry are all stored in the songs table.
*/
DROP TABLE IF EXISTS songs;
CREATE TABLE songs (
songid INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
entryid INTEGER(10) NOT NULL,
position INTEGER(10) NOT NULL,
title VARCHAR(200) NOT NULL,
location VARCHAR(200) NOT NULL,
duration INTEGER(10) NOT NULL,
votes VARCHAR(255) NOT NULL,
CONSTRAINT fk_songs_entries FOREIGN KEY (entryid)
REFERENCES entries (entryid) ON DELETE CASCADE
);
CREATE INDEX entryid_idx ON songs (entryid);
/**
* Categories are generally referred to by their name which is defined in
* this table.
*/
DROP TABLE IF EXISTS category_names;
CREATE TABLE category_names (
categoryid INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
UNIQUE (name)
);
/**
* Entries are mapped into one or more categories via this table.
*/
DROP TABLE IF EXISTS category_map;
CREATE TABLE category_map (
categoryid INTEGER(10) NOT NULL,
entryid INTEGER(10) NOT NULL,
CONSTRAINT fk_category_map_category_names FOREIGN KEY (categoryid)
REFERENCES category_names (categoryid) ON DELETE CASCADE,
CONSTRAINT fk_category_map_entries FOREIGN KEY (entryid)
REFERENCES entries (entryid) ON DELETE CASCADE,
UNIQUE (categoryid, entryid)
);