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