--- backup/api.install 2007-10-19 21:39:16.000000000 -0400 +++ api.install 2007-11-30 18:54:48.609375000 -0500 @@ -1,63 +1,68 @@ array( + 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => 1, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => '255', 'not null' => 1, 'default' => ''), + 'directory' => array('type' => 'varchar', 'length' => '255', 'not null' => 1, 'default' => '')), + 'primary key' => array('branch_name'), +); +$schema['api_documentation'] = array( + 'fields' => array( + 'did' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1, 'default' => 0, 'disp-width' => '10'), + 'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => 1, 'default' => ''), + 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => 1, 'default' => ''), + 'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => 1, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => '255', 'not null' => 1, 'default' => ''), + 'file_name' => array('type' => 'varchar', 'length' => '127', 'not null' => 1, 'default' => ''), + 'summary' => array('type' => 'text', 'size' => 'medium', 'not null' => 1), + 'documentation' => array('type' => 'text', 'size' => 'medium', 'not null' => 1), + 'code' => array('type' => 'text', 'size' => 'medium', 'not null' => 1)), + 'primary key' => array('did'), + 'unique keys' => array( + 'object_name' => array('object_name', 'branch_name', 'object_type')), + 'indexes' => array( + 'branch_name' => array('branch_name'), + 'title' => array('title')), +); + +$schema['api_file'] = array( + 'fields' => array( + 'did' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1, 'default' => 0, 'disp-width' => '10'), + 'modified' => array('type' => 'int', 'not null' => 1, 'default' => 0, 'disp-width' => '11'), + 'version' => array('type' => 'varchar', 'length' => '255', 'not null' => 1, 'default' => ''), + 'found' => array('type' => 'int', 'unsigned' => 1, 'size' => 'tiny', 'not null' => 1, 'default' => 0, 'disp-width' => '1')), + 'primary key' => array('did'), +); + +$schema['api_function'] = array( + 'fields' => array( + 'did' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1, 'default' => 0, 'disp-width' => '10'), + 'signature' => array('type' => 'varchar', 'length' => '255', 'not null' => 1, 'default' => ''), + 'start_line' => array('type' => 'int', 'not null' => 1, 'default' => 0, 'disp-width' => '10'), + 'parameters' => array('type' => 'text', 'size' => 'medium', 'not null' => 1), + 'return' => array('type' => 'text', 'size' => 'medium', 'not null' => 1)), + 'primary key' => array('did'), +); + +$schema['api_reference_storage'] = array( + 'fields' => array( + 'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => 1, 'default' => ''), + 'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => 1, 'default' => ''), + 'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => 1, 'default' => ''), + 'from_did' => array('type' => 'int', 'not null' => 1, 'default' => 0, 'disp-width' => '11'), + 'to_did' => array('type' => 'int', 'not null' => 1, 'default' => 0, 'disp-width' => '11')), + 'indexes' => array( + 'object_ref' => array('object_name', 'branch_name', 'object_type')), +); - case 'pgsql': - break; - } + return $schema; +} + +function api_install() { + drupal_install_schema('api'); } function api_update_1() { @@ -66,17 +71,7 @@ function api_update_1() { function api_update_2() { $ret = array(); - - switch ($GLOBALS['db_type']) { - case 'pgsql': - db_add_column($ret, 'api_file', 'found', 'smallint', array('not null' => TRUE, 'default' => 0)); - break; - - case 'mysql': - case 'mysqli': - $ret[] = update_sql("ALTER TABLE {api_file} ADD COLUMN found tinyint(1) UNSIGNED NOT NULL DEFAULT 0"); - break; - } + db_add_column($ret, 'api_file', 'found', 'tinyint', array('not null' => TRUE, 'default' => 0, 'length' => 1, 'unsigned' => TRUE)); return $ret; } @@ -98,26 +93,13 @@ function api_update_3() { function api_update_4() { $return = array(); - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $return[] = update_sql('ALTER TABLE {api_documentation} ADD INDEX (branch_name)'); - break; - } - + db_add_index($return, 'api_documentation', '', 'branch_name'); return $return; } function api_update_5() { $return = array(); - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $return[] = update_sql('ALTER TABLE {api_documentation} ADD INDEX (title)'); - break; - } + db_add_index($return, 'api_documentation', '', 'title'); return $return; } @@ -128,34 +110,48 @@ function api_update_5() { */ function api_update_6() { $return = array(); + $schema['api_reference_storage'] = array( + 'fields' => array( + 'object_name' => array( + 'type' => 'varchar', + 'length' => '127', + 'not null' => TRUE, + 'default' => ''), + 'branch_name' => array( + 'type' => 'varchar', + 'length' => 31, + 'not null' => TRUE, + 'default' => ''), + 'object_type' => array( + 'type' => 'varchar', + 'length' => 31, + 'not null' => TRUE, + 'default' => ''), + 'from_did' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => '0'), + 'to_did' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => '0'), + ), + 'indexes' => array( + 'api_documentation_object_ref' => array('object_name', 'branch_name', 'object_type'), + ), + ); + + db_rename_table($return, 'api_reference_storage', 'api_reference_storage_old'); + db_create_table($return, 'api_reference_storage', $schema['api_reference_storage']); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $return[] = update_sql('RENAME TABLE {api_reference_storage} TO {api_reference_storage_old}'); - $return[] = update_sql("CREATE TABLE {api_reference_storage} ( - object_name varchar(127) NOT NULL default '', - branch_name varchar(31) NOT NULL default '', - object_type varchar(31) NOT NULL default '', - from_did int NOT NULL default '0', - to_did int NOT NULL default '0', - INDEX object_ref (object_name,branch_name,object_type) - ) /*!40100 DEFAULT CHARACTER SET utf8 */"); - break; - } $result = db_query('SELECT * FROM {api_reference_storage}'); while ($row = db_fetch_object($result)) { list($branch_name, $to_type, $to_name) = unserialize($row->reference_key); db_query("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did) VALUES ('%s', '%s', '%s', %d)", $to_name, $branch_name, $to_type, $row->from_did); } - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $return[] = update_sql('DROP TABLE {api_reference_storage_old}'); - break; - } + + db_drop_table($return, 'api_reference_storage_old'); return $return; } @@ -166,23 +162,24 @@ function api_update_6() { function api_update_7() { $return = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': + $return[] = update_sql("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did, to_did) SELECT d.object_name, d.branch_name, d.object_type, r.from_did, r.to_did FROM {api_reference} r INNER JOIN {api_documentation} d ON d.did = r.to_did"); + db_drop_table($return, 'api_reference'); + return $return; +} + +/** + * Move data from {api_reference} to {api_reference_storage}. + +function api_update_7() { + $return = array(); $return[] = update_sql("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did, to_did) SELECT d.object_name, d.branch_name, d.object_type, r.from_did, r.to_did FROM {api_reference} r INNER JOIN {api_documentation} d ON d.did = r.to_did"); $return[] = update_sql('DROP TABLE {api_reference}'); break; - } - return $return; } - +*/ function api_uninstall() { - db_query('DROP TABLE IF EXISTS {api_branch}'); - db_query('DROP TABLE IF EXISTS {api_documentation}'); - db_query('DROP TABLE IF EXISTS {api_file}'); - db_query('DROP TABLE IF EXISTS {api_function}'); - db_query('DROP TABLE IF EXISTS {api_reference_storage}'); + drupal_uninstall_schema('api'); variable_del('api_default_branch'); variable_del('api_php_funcsummary'); variable_del('api_php_funcpath');