00001 <?php
00002
00003
00004
00022 function icbasic_install() {
00023
00024 global $db_url;
00025 if (strpos($db_url['default'], 'pgsql://') === FALSE && strpos($db_url, 'pgsql://') === FALSE) {
00026 drupal_set_message("The icbasic module was not installed: it requires a PostgreSQL database due to integration with GMOD and chado ($db_url).", 'error', FALSE);
00027 return FALSE;
00028 }
00029
00030 drupal_install_schema('icbasic');
00031
00032 db_query('ALTER table {ic_feature} add timestamp timestamp with time zone default now()');
00033 db_query('ALTER table {ic_resource} add timestamp timestamp with time zone default now()');
00034 db_query("INSERT INTO {ic_organism} (tax_order,tax_family,genus,species) VALUES ('general','general','general','general')");
00035 db_query("INSERT INTO {ic_db} (name) VALUES ('local publication')");
00036 db_query("INSERT INTO {ic_db} (name) VALUES ('local study')");
00037 db_query("INSERT INTO {ic_db} (name) VALUES ('local feature')");
00038 db_query("INSERT INTO {ic_db} (name) VALUES ('local resource')");
00039 db_query("INSERT INTO {ic_dbxref} (db_id,accession) VALUES (1,'Unpublished')");
00040 db_query("INSERT INTO {ic_cv} (name) VALUES ('resource_property')");
00041 db_query("INSERT INTO {ic_cv} (name) VALUES ('relationship')");
00042 db_query("INSERT INTO {ic_cvterm} (cv_id,name) VALUES ((SELECT cv_id from {ic_cv} where name='relationship'),'uses')");
00043 db_query("INSERT INTO {ic_cvterm} (cv_id,name) VALUES ((SELECT cv_id from {ic_cv} where name='relationship'),'part_of')");
00044 db_query("INSERT INTO {ic_pub} (dbxref_id,uniquename) VALUES (1,'none')");
00045 }
00046
00053 function icbasic_uninstall() {
00054
00055 $drop_sql = 'DROP TABLE %s CASCADE';
00056 $tables = array('{ic_pub}', '{ic_db}', '{ic_dbxref}', '{ic_author}', '{ic_pub_author}', '{ic_organism}', '{ic_feature}', '{ic_cv}',
00057 '{ic_cvterm}', '{ic_feature_cvterm}', '{ic_featureprop}', '{ic_resource}', '{ic_resource_cvterm}', '{ic_resourceprop}',
00058 '{ic_resource_resource}',
00059 );
00060 $table_str = implode(',', $tables);
00061 db_query($drop_sql, $table_str);
00062 }
00063
00069 function icbasic_enable() {}
00070
00076 function icbasic_disable() {}
00077
00086 function icbasic_schema() {
00087 $schema['ic_pub'] = array(
00088 'fields' => array(
00089 'pub_id' => array(
00090 'type' => 'serial',
00091 'not null' => TRUE,
00092 ),
00093 'dbxref_id' => array(
00094 'type' => 'int',
00095 'not null' => TRUE,
00096 ), 'type_id' => array(
00097 'type' => 'int',
00098 ),
00099 'uniquename' => array(
00100 'type' => 'text',
00101 'not null' => TRUE,
00102 ),
00103 'passkey' => array(
00104 'type' => 'varchar',
00105 'length' => 15,
00106 'not null' => FALSE,
00107 ),
00108 ),
00109 'unique keys' => array(
00110 'pub_uidx1' => array('uniquename'),
00111 ),
00112 'primary key' => array('pub_id'),
00113 );
00114 $schema['ic_db'] = array(
00115 'fields' => array(
00116 'db_id' => array(
00117 'type' => 'serial',
00118 'not null' => TRUE,
00119 ),
00120 'name' => array(
00121 'type' => 'text',
00122 'not null' => TRUE,
00123 ), 'description' => array(
00124 'type' => 'text',
00125 ),
00126 ),
00127 'unique keys' => array(
00128 'db_uidx1' => array('name'),
00129 ),
00130 'primary key' => array('db_id'),
00131 );
00132 $schema['ic_dbxref'] = array(
00133 'fields' => array(
00134 'dbxref_id' => array(
00135 'type' => 'serial',
00136 'not null' => TRUE,
00137 ),
00138 'accession' => array(
00139 'type' => 'varchar',
00140 'length' => 255,
00141 'not null' => TRUE,
00142 ), 'description' => array(
00143 'type' => 'text',
00144 ),
00145 'db_id' => array(
00146 'type' => 'int',
00147 'not null' => TRUE,
00148 ),
00149 ),
00150 'unique keys' => array(
00151 'pub_uidx1' => array('db_id', 'accession'),
00152 ),
00153 'primary key' => array('dbxref_id'),
00154 );
00155 $schema['ic_author'] = array(
00156 'fields' => array(
00157 'author_id' => array(
00158 'type' => 'serial',
00159 'not null' => TRUE,
00160 ),
00161 'first_names' => array(
00162 'type' => 'varchar',
00163 'length' => 255,
00164 'not null' => TRUE,
00165 ),
00166 'last_names' => array(
00167 'type' => 'varchar',
00168 'length' => 255,
00169 'not null' => TRUE,
00170 ),
00171 'email' => array(
00172 'type' => 'varchar',
00173 'length' => 127,
00174 'not null' => TRUE,
00175 ),
00176 'address' => array(
00177 'type' => 'text',
00178 ),
00179 ),
00180 'primary key' => array('author_id'),
00181 'unique keys' => array(
00182 array('last_names', 'first_names', 'email'),
00183 ),
00184 );
00185 $schema['ic_pub_author'] = array(
00186 'fields' => array(
00187 'author_id' => array(
00188 'type' => 'int',
00189 'not null' => TRUE,
00190 ), 'pub_id' => array(
00191 'type' => 'int',
00192 'not null' => TRUE,
00193 ),
00194 'rank' => array(
00195 'type' => 'int',
00196 'not null' => TRUE,
00197 ),
00198 ),
00199 'primary key' => array('author_id', 'pub_id', 'rank'),
00200 );
00201 $schema['ic_organism'] = array(
00202 'fields' => array(
00203 'organism_id' => array(
00204 'type' => 'serial',
00205 'not null' => TRUE,
00206 ), 'tax_order' => array(
00207 'type' => 'varchar',
00208 'not null' => TRUE,
00209 'length' => 128,
00210 ), 'tax_family' => array(
00211 'type' => 'varchar',
00212 'not null' => TRUE,
00213 'length' => 128,
00214 ), 'genus' => array(
00215 'type' => 'varchar',
00216 'not null' => TRUE,
00217 'length' => 128,
00218 ), 'species' => array(
00219 'type' => 'varchar',
00220 'not null' => TRUE,
00221 'length' => 128,
00222 ), 'ncbi_taxid' => array(
00223 'type' => 'int',
00224 ),
00225 ),
00226 'primary key' => array('organism_id'),
00227 'unique keys' => array(
00228 'organism_uidx1' => array('tax_order', 'tax_family', 'genus', 'species'),
00229 ),
00230 );
00231 $schema['ic_feature'] = array(
00232 'fields' => array(
00233 'feature_id' => array(
00234 'type' => 'serial',
00235 'not null' => TRUE,
00236 ), 'uniquename' => array(
00237 'type' => 'text',
00238 'not null' => TRUE,
00239 ), 'dbxref_id' => array(
00240 'type' => 'int',
00241 'not null' => TRUE,
00242 ), 'type_id' => array(
00243 'type' => 'int',
00244 'not null' => TRUE,
00245 ), 'residues' => array(
00246 'type' => 'text',
00247 ), 'organism_id' => array(
00248 'type' => 'int',
00249 'not null' => TRUE,
00250 'default' => 1,
00251 ), 'passkey' => array(
00252 'type' => 'varchar',
00253 'length' => 15,
00254 'not null' => TRUE,
00255 ),
00256 ),
00257 'primary key' => array('feature_id'),
00258 'unique keys' => array(
00259 'feature_uidx1' => array('uniquename'),
00260 ),
00261 );
00262 $schema['ic_cv'] = array(
00263 'fields' => array(
00264 'cv_id' => array(
00265 'type' => 'serial',
00266 'not null' => TRUE,
00267 ), 'name' => array(
00268 'type' => 'text',
00269 'not null' => TRUE,
00270 ),
00271 ),
00272 'primary key' => array('cv_id'),
00273 'unique keys' => array(
00274 'cv_uidx1' => array('name'),
00275 ),
00276 );
00277 $schema['ic_cvterm'] = array(
00278 'fields' => array(
00279 'cvterm_id' => array(
00280 'type' => 'serial',
00281 'not null' => TRUE,
00282 ), 'name' => array(
00283 'type' => 'text',
00284 'not null' => TRUE,
00285 ), 'cv_id' => array(
00286 'type' => 'int',
00287 'not null' => TRUE,
00288 ), 'definition' => array(
00289 'type' => 'text',
00290 ),
00291 ),
00292 'primary key' => array('cvterm_id'),
00293 'unique keys' => array(
00294 'cvterm_uidx1' => array('name', 'cv_id'),
00295 ),
00296 );
00297 $schema['ic_feature_cvterm'] = array(
00298 'fields' => array(
00299 'feature_cvterm_id' => array(
00300 'type' => 'serial',
00301 'not null' => TRUE,
00302 ), 'feature_id' => array(
00303 'type' => 'int',
00304 'not null' => TRUE,
00305 ), 'cvterm_id' => array(
00306 'type' => 'int',
00307 'not null' => TRUE,
00308 ),
00309 ),
00310 'primary key' => array('feature_cvterm_id'),
00311 'indexes' => array(
00312 'feature_cvterm_idx1' => array('feature_id', 'cvterm_id'),
00313 ),
00314 );
00315 $schema['ic_featureprop'] = array(
00316 'fields' => array(
00317 'featureprop_id' => array(
00318 'type' => 'serial',
00319 'not null' => TRUE,
00320 ), 'feature_id' => array(
00321 'type' => 'int',
00322 'not null' => TRUE,
00323 ), 'type_id' => array(
00324 'type' => 'int',
00325 'not null' => TRUE,
00326 ), 'value' => array(
00327 'type' => 'text',
00328 ),
00329 ),
00330 'primary key' => array('featureprop_id'),
00331 );
00332 $schema['ic_resource'] = array(
00333 'fields' => array(
00334 'resource_id' => array(
00335 'type' => 'serial',
00336 'not null' => TRUE,
00337 ), 'uniquename' => array(
00338 'type' => 'text',
00339 'not null' => TRUE,
00340
00341 ), 'organism_id' => array(
00342 'type' => 'int',
00343 'not null' => TRUE,
00344 'default' => 1,
00345
00346 ), 'dbxref_id' => array(
00347 'type' => 'int',
00348 'not null' => TRUE,
00349 ), 'passkey' => array(
00350 'type' => 'varchar',
00351 'length' => 15,
00352 'not null' => FALSE,
00353
00354 ), 'type_id' => array(
00355 'type' => 'int',
00356 'not null' => TRUE,
00357 ), 'description' => array(
00358 'type' => 'text',
00359 ),
00360 ), 'unique keys' => array(
00361 'resource_uidx1' => array('uniquename'),
00362 ),
00363 'primary key' => array('resource_id'),
00364 );
00365 $schema['ic_resource_cvterm'] = array(
00366 'fields' => array(
00367 'resource_cvterm_id' => array(
00368 'type' => 'serial',
00369 'not null' => TRUE,
00370 ), 'resource_id' => array(
00371 'type' => 'int',
00372 'not null' => TRUE,
00373 ), 'cvterm_id' => array(
00374 'type' => 'int',
00375 'not null' => TRUE,
00376 ),
00377 ),
00378 'primary key' => array('resource_cvterm_id'),
00379 'indexes' => array(
00380 'resource_cvterm_idx1' => array('resource_id', 'cvterm_id'),
00381 ),
00382 );
00383 $schema['ic_resourceprop'] = array(
00384 'fields' => array(
00385 'resourceprop_id' => array(
00386 'type' => 'serial',
00387 'not null' => TRUE,
00388 ), 'resource_id' => array(
00389 'type' => 'int',
00390 'not null' => TRUE,
00391 ), 'type_id' => array(
00392 'type' => 'int',
00393 'not null' => TRUE,
00394 ), 'value' => array(
00395 'type' => 'text',
00396 ), 'rank' => array(
00397 'type' => 'int',
00398 'default' => 0,
00399 ),
00400 ),
00401 'primary key' => array('resourceprop_id'),
00402 );
00403 $schema['ic_resource_resource'] = array(
00404 'fields' => array(
00405 'resource_resource_id' => array(
00406 'type' => 'serial',
00407 'not null' => TRUE,
00408 ), 'subject_id' => array(
00409 'type' => 'int',
00410 'not null' => TRUE,
00411 ), 'object_id' => array(
00412 'type' => 'int',
00413 'not null' => TRUE,
00414 ), 'type_id' => array(
00415 'type' => 'int',
00416 'not null' => TRUE,
00417 ),
00418 ),
00419 'primary key' => array('resource_resource_id'),
00420 'unique keys' => array(
00421 'resource_resource_uidx1' => array('subject_id', 'object_id'),
00422 ),
00423 );
00424
00425 return $schema;
00426 }
00427