From 470048442aaac7c0de287795f44cea41331fc5f6 Mon Sep 17 00:00:00 2001 From: mdb Date: Sun, 10 Dec 2000 07:00:47 +0000 Subject: [PATCH] SQL to create the music repository. git-svn-id: https://samskivert.googlecode.com/svn/trunk@30 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../robodj/src/sql/create_repository.mysql | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 projects/robodj/src/sql/create_repository.mysql diff --git a/projects/robodj/src/sql/create_repository.mysql b/projects/robodj/src/sql/create_repository.mysql new file mode 100644 index 00000000..f20ebdd4 --- /dev/null +++ b/projects/robodj/src/sql/create_repository.mysql @@ -0,0 +1,62 @@ +/** + * $Id: create_repository.mysql,v 1.1 2000/12/10 07:00:47 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, + + 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) +);