view implementations/meredith/database-setup.lisp @ 263:df5d60cda9a2

add linked-event superclass to mtp-event
author Jamie Forth <j.forth@gold.ac.uk>
date Sun, 10 Apr 2011 10:24:37 +0100
parents 4eceac78e7c6
children
line wrap: on
line source
(cl:in-package #:amuse-meredith)

(defun create-meredith-tables (database)
  (%create-compositions-table database)
  (%create-events-table database))

(defun drop-meredith-tables (database)
  (%drop-compositions-table database)
  (%drop-events-table database))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Helper functions

(defun %create-compositions-table (database)
  #.(clsql:locally-enable-sql-reader-syntax)
  (clsql:create-table "meredith_compositions"
		      '(([|composition-id|] clsql:smallint :unsigned
			 :not-null :auto-increment :primary-key)
			([|description|] (clsql:varchar 255)
			 :not-null))
		      :database database
		      :transactions t)
  #.(clsql:locally-disable-sql-reader-syntax))

(defun %create-events-table (database)
  #.(clsql:locally-enable-sql-reader-syntax)
  (clsql:create-table "meredith_events"
		'(([|composition-id|] clsql:smallint :unsigned
		   :not-null)
		  ([|event-id|] clsql:smallint :unsigned
		   :not-null :auto-increment :unique)
		  ([|tatum-on|] clsql:smallint :unsigned :not-null)
		  ([|pitch-name|] (clsql:varchar 32) :not-null)
		  ([|tatum-dur|] clsql:smallint :unsigned :not-null)
		  ([|voice|] clsql:smallint :unsigned :not-null)
		  ([|tactus-on|] clsql::float :unsigned :not-null)
		  ([|tactus-dur|] clsql::float :unsigned :not-null)
		  ([|crot-on|] clsql::float :unsigned :not-null)
		  ([|crot-dur|] clsql::float :unsigned :not-null)
		  ([|midi-note-number|] clsql:smallint :unsigned :not-null)
		  ([|chrom-pitch|] clsql:smallint :unsigned :not-null)
		  ([|morph-pitch|] clsql:smallint :unsigned :not-null)
		  ([|tatum-on-ms|] clsql:smallint :unsigned :not-null)
		  ([|tatum-dur-ms|] clsql:smallint :unsigned :not-null)
		  ([|beat-on-ms|] clsql:smallint :unsigned :not-null)
		  ([|beat-dur-ms|] clsql:smallint :unsigned :not-null)
		  ([|crot-on-ms|] clsql:smallint :unsigned :not-null)
		  ([|crot-dur-ms|] clsql:smallint :unsigned :not-null))
		:constraints '("PRIMARY KEY (composition_id, event_id)")
		:database database
		:transactions t)
  #.(clsql:locally-disable-sql-reader-syntax))

(defun %drop-compositions-table (database)
  (clsql:drop-table "meredith_compositions"
		    :database database))

(defun %drop-events-table (database)
  (clsql:drop-table "meredith_events"
		    :database database))