annotate implementations/midi-db/db-setup.lisp @ 330:2fbff655ba47 tip

Removed cpitch-adj and cents SQL columns
author Jeremy Gow <jeremy.gow@gmail.com>
date Mon, 21 Jan 2013 11:08:11 +0000
parents f99fd6a7bbfc
children
rev   line source
j@310 1 (cl:in-package #:amuse-midi-db)
j@310 2
j@310 3 ;; Creating tables
j@310 4
j@310 5 (defun create-midi-db-tables (database)
j@310 6 (%create-midi-collections-table database)
j@310 7 (%create-midi-compositions-table database)
j@310 8 (%create-midi-events-table database)
j@310 9 (%create-midi-tempi-table database)
j@310 10 (%create-midi-timesigs-table database)
j@310 11 (%create-midi-keysigs-table database))
j@310 12
j@310 13 (defun %create-midi-collections-table (database)
j@310 14 #.(clsql:locally-enable-sql-reader-syntax)
j@310 15 (clsql:create-table "midi_db_collections"
j@310 16 '(([|collection-id|] clsql:smallint :unsigned
j@310 17 :not-null :auto-increment :primary-key)
j@310 18 ([|collection-name|] (clsql:varchar 255)
j@310 19 :not-null)
j@310 20 ([|description|] (clsql:varchar 255)
j@310 21 :not-null))
j@310 22 :database database
j@310 23 :transactions t)
j@310 24 #.(clsql:locally-disable-sql-reader-syntax))
j@310 25
j@310 26 (defun %create-midi-compositions-table (database)
j@310 27 (clsql:execute-command "
j@310 28 CREATE TABLE midi_db_compositions (
j@310 29 collection_id SMALLINT UNSIGNED NOT NULL,
j@310 30 composition_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@310 31 filename VARCHAR(255) NOT NULL,
j@310 32 timebase SMALLINT UNSIGNED NOT NULL,
j@310 33 start INT UNSIGNED NOT NULL,
j@310 34 duration INT UNSIGNED NOT NULL,
j@310 35 owner CHAR(16) NULL,
j@310 36 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@310 37 creation_timestamp TIMESTAMP NULL,
j@310 38 deletion_timestamp TIMESTAMP NULL,
j@310 39 INDEX midi_composition_index (
j@310 40 collection_id, composition_id, version))
j@310 41 engine = innodb;"
j@310 42 :database database)
j@310 43 (%create-midi-composition-header-triggers database))
j@310 44
j@310 45 (defun %create-midi-composition-header-triggers (database)
j@310 46 (clsql:execute-command "
j@310 47 CREATE TRIGGER pre_insert_comp BEFORE INSERT ON midi_db_compositions
j@310 48 FOR EACH ROW
j@310 49 BEGIN
j@310 50 SET NEW.owner = SUBSTRING_INDEX(USER(),'@',1);
j@310 51 SET NEW.creation_timestamp = CURRENT_TIMESTAMP;
j@310 52 END;"
j@310 53 :database database))
j@310 54
j@310 55 (defun %create-midi-events-table (database)
j@310 56 (clsql:execute-command "
j@310 57 CREATE TABLE midi_db_events (
j@310 58 collection_id SMALLINT UNSIGNED NOT NULL,
j@310 59 composition_id SMALLINT UNSIGNED NOT NULL,
j@310 60 event_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@310 61 track SMALLINT UNSIGNED NOT NULL,
j@310 62 channel TINYINT UNSIGNED NOT NULL,
j@310 63 patch TINYINT UNSIGNED NOT NULL,
j@310 64 pitch TINYINT UNSIGNED NOT NULL,
j@310 65 velocity TINYINT UNSIGNED NOT NULL,
j@310 66 start INTEGER UNSIGNED NOT NULL,
j@310 67 duration INTEGER UNSIGNED NOT NULL,
j@310 68 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@310 69 INDEX collection_composition (collection_id, composition_id))
j@310 70 engine = innodb;"
j@310 71 :database database))
j@310 72
j@310 73 (defun %create-midi-tempi-table (database)
j@310 74 (clsql:execute-command "
j@310 75 CREATE TABLE midi_db_tempi (
j@310 76 collection_id SMALLINT UNSIGNED NOT NULL,
j@310 77 composition_id SMALLINT UNSIGNED NOT NULL,
j@310 78 constituent_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@310 79 start INT UNSIGNED NOT NULL,
j@310 80 duration INT UNSIGNED NOT NULL,
j@310 81 microsecs_per_crotchet INTEGER UNSIGNED NOT NULL,
j@310 82 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@310 83 INDEX collection_composition (collection_id, composition_id, constituent_id))
j@310 84 engine = innodb;"
j@310 85 :database database))
j@310 86
j@310 87 (defun %create-midi-timesigs-table (database)
j@310 88 (clsql:execute-command "
j@310 89 CREATE TABLE midi_db_timesigs (
j@310 90 collection_id SMALLINT UNSIGNED NOT NULL,
j@310 91 composition_id SMALLINT UNSIGNED NOT NULL,
j@310 92 constituent_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@310 93 start INT UNSIGNED NOT NULL,
j@310 94 duration INT UNSIGNED NOT NULL,
j@310 95 numerator TINYINT UNSIGNED NOT NULL,
j@310 96 denominator TINYINT UNSIGNED NOT NULL,
j@310 97 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@310 98 INDEX collection_composition (collection_id, composition_id, constituent_id))
j@310 99 engine = innodb;"
j@310 100 :database database))
j@310 101
j@310 102 (defun %create-midi-keysigs-table (database)
j@310 103 (clsql:execute-command "
j@310 104 CREATE TABLE midi_db_keysigs (
j@310 105 collection_id SMALLINT UNSIGNED NOT NULL,
j@310 106 composition_id SMALLINT UNSIGNED NOT NULL,
j@310 107 constituent_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@310 108 start INT UNSIGNED NOT NULL,
j@310 109 duration INT UNSIGNED NOT NULL,
j@310 110 mode TINYINT UNSIGNED NOT NULL,
j@310 111 sharp_count TINYINT UNSIGNED NOT NULL,
j@310 112 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@310 113 INDEX collection_composition (collection_id, composition_id, constituent_id))
j@310 114 engine = innodb;"
j@310 115 :database database))
j@310 116
j@310 117 ;; Deleting tables
j@310 118
j@310 119 (defun drop-midi-db-tables (database)
j@310 120 (%drop-midi-collections-table database)
j@310 121 (%drop-midi-compositions-table database)
j@310 122 (%drop-midi-events-table database)
j@310 123 (%drop-midi-tempi-table database)
j@310 124 (%drop-midi-timesigs-table database)
j@310 125 (%drop-midi-keysigs-table database))
j@310 126
j@310 127 (defun %drop-midi-collections-table (database)
j@310 128 (clsql:drop-table "midi_db_collections"
j@310 129 :if-does-not-exist :ignore
j@310 130 :database database))
j@310 131
j@310 132 (defun %drop-midi-compositions-table (database)
j@310 133 (clsql:drop-table "midi_db_compositions"
j@310 134 :if-does-not-exist :ignore
j@310 135 :database database))
j@310 136
j@310 137 (defun %drop-midi-events-table (database)
j@310 138 (clsql:drop-table "midi_db_events"
j@310 139 :if-does-not-exist :ignore
j@310 140 :database database))
j@310 141
j@310 142 (defun %drop-midi-constituent-headers-table (database)
j@310 143 (clsql:drop-table "midi_db_constituent_headers"
j@310 144 :if-does-not-exist :ignore
j@310 145 :database database))
j@310 146
j@310 147 (defun %drop-midi-tempi-table (database)
j@310 148 (clsql:drop-table "midi_db_tempi"
j@310 149 :if-does-not-exist :ignore
j@310 150 :database database))
j@310 151
j@310 152 (defun %drop-midi-timesigs-table (database)
j@310 153 (clsql:drop-table "midi_db_timesigs"
j@310 154 :if-does-not-exist :ignore
j@310 155 :database database))
j@310 156
j@310 157 (defun %drop-midi-keysigs-table (database)
j@310 158 (clsql:drop-table "midi_db_keysigs"
j@310 159 :if-does-not-exist :ignore
j@310 160 :database database))