annotate base/charm/database-setup.lisp @ 258:aac79c0ac1b9

add within-short-bar-p, and use this to correctly calculate the ioi-from-bar of anacruses
author Jamie Forth <j.forth@gold.ac.uk>
date Thu, 24 Feb 2011 18:50:38 +0000
parents b5ffec94ae6d
children
rev   line source
j@253 1 (cl:in-package #:amuse-charm)
j@253 2
j@253 3 ;;;=====================================================================
j@253 4 ;;; CHARM database setup functions
j@253 5 ;;;=====================================================================
j@253 6
j@253 7 (defun create-charm-db-tables (database)
j@253 8 (%create-constituent-header-table database)
j@253 9 (%create-constituent-particle-table database)
j@253 10 (%create-constituent-stored-routines database))
j@253 11
j@253 12 (defun drop-charm-db-tables (database)
j@253 13 (%drop-constituent-header-table database)
j@253 14 (%drop-constituent-particle-table database)
j@253 15 (%drop-constituent-stored-routines database))
j@253 16
j@253 17
j@253 18 ;;;=====================================================================
j@253 19 ;;; Helper functions
j@253 20 ;;;=====================================================================
j@253 21
j@253 22 (defun %create-constituent-header-table (database)
j@253 23 (clsql:execute-command "
j@253 24 CREATE TABLE charm_constituent_headers (
j@253 25 constituent_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@253 26 implementation_id SMALLINT UNSIGNED NOT NULL,
j@253 27 parent_id INT UNSIGNED NOT NULL,
j@253 28 #start_time INTEGER UNSIGNED NOT NULL,
j@253 29 #duration INTEGER UNSIGNED NOT NULL,
j@253 30 ext_properties VARCHAR(255) NOT NULL,
j@253 31 int_properties VARCHAR(255) NOT NULL,
j@253 32 owner CHAR(16) NULL,
j@253 33 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@253 34 creation_timestamp TIMESTAMP NULL,
j@253 35 deletion_timestamp TIMESTAMP NULL,
j@253 36 INDEX impl_comp_index (implementation_id, parent_id))
j@253 37 engine = innodb;"
j@253 38 :database database)
j@253 39 (%create-constituent-header-triggers database))
j@253 40
j@253 41 (defun %create-constituent-header-triggers (database)
j@253 42 (clsql:execute-command "
j@253 43 CREATE TRIGGER pre_insert BEFORE INSERT ON charm_constituent_headers
j@253 44 FOR EACH ROW
j@253 45 BEGIN
j@253 46 SET NEW.owner = SUBSTRING_INDEX(USER(),'@',1);
j@253 47 SET NEW.creation_timestamp = CURRENT_TIMESTAMP;
j@253 48 #SET NEW.implementation_id = @current_impl;
j@253 49 END;"
j@253 50 :database database))
j@253 51
j@253 52 (defun %create-constituent-particle-table (database)
j@253 53 (clsql:execute-command "
j@253 54 CREATE TABLE charm_constituent_particles (
j@253 55 constituent_id BIGINT UNSIGNED NOT NULL,
j@253 56 particle_id BIGINT UNSIGNED NOT NULL,
j@253 57 particle_type SET('e', 'c') NOT NULL,
j@253 58 version_added SMALLINT UNSIGNED NOT NULL,
j@253 59 version_removed SMALLINT UNSIGNED NULL,
j@253 60 INDEX particle_index (constituent_id))
j@253 61 engine = innodb;"
j@253 62 :database database))
j@253 63
j@253 64 (defun %drop-constituent-header-table (database)
j@253 65 (clsql:drop-table "charm_constituent_headers"
j@253 66 :database database
j@253 67 :if-does-not-exist :ignore))
j@253 68
j@253 69 (defun %drop-constituent-particle-table (database)
j@253 70 (clsql:drop-table "charm_constituent_particles"
j@253 71 :database database
j@253 72 :if-does-not-exist :ignore))
j@253 73
j@253 74 (defun %drop-constituent-stored-routines (database)
j@253 75 (clsql:execute-command "
j@253 76 DROP FUNCTION constituent_header_exists"
j@253 77 :database database))
j@253 78
j@253 79
j@253 80 ;;;=====================================================================
j@253 81 ;;; Other server-side routines
j@253 82 ;;;=====================================================================
j@253 83
j@253 84 (defun %create-constituent-stored-routines (database)
j@253 85 (clsql:execute-command "
j@253 86 CREATE FUNCTION constituent_header_exists (
j@253 87 #start int unsigned,
j@253 88 #dur int unsigned,
j@253 89 impl_id SMALLINT UNSIGNED,
j@253 90 par_id INT UNSIGNED,
j@253 91 external varchar(255),
j@253 92 intrinsic varchar(255))
j@253 93 RETURNS boolean
j@253 94 RETURN EXISTS(SELECT constituent_id
j@253 95 FROM charm_constituent_headers
j@253 96 WHERE implementation_id = impl_id
j@253 97 AND parent_id = par_id
j@253 98 AND ext_properties = external
j@253 99 AND int_properties = intrinsic);"
j@253 100 :database database))