From e12862672e7a0c8a62f4b26e11a6758093fe6fd5 Mon Sep 17 00:00:00 2001 From: Brandon Bergren <bdragon@rtk0.net> Date: Tue, 15 Jul 2008 21:16:54 +0000 Subject: [PATCH] schema api-ification --- gmap_taxonomy.install | 77 +++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/gmap_taxonomy.install b/gmap_taxonomy.install index 3099dfc..f3cb320 100644 --- a/gmap_taxonomy.install +++ b/gmap_taxonomy.install @@ -1,39 +1,51 @@ <?php // $Id$ +/** + * @file + * gmap_taxonomy install routines. + */ + /** * Implementation of hook_install(). */ function gmap_taxonomy_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {gmap_taxonomy_term} ( - tid int(10) unsigned NOT NULL default '0', - marker varchar(32), - PRIMARY KEY tid(tid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */"); - db_query("CREATE TABLE {gmap_taxonomy_node} ( - nid int(10) unsigned NOT NULL default '0', - vid int(10) unsigned NOT NULL default '0', - tid int(10) unsigned NOT NULL default '0', - marker varchar(32), - PRIMARY KEY vid(vid), - INDEX nid(nid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */"); - break; - case 'pgsql': - //@@@ - break; - } + drupal_install_schema('gmap_taxonomy'); } /** * Implementation of hook_uninstall(). */ function gmap_taxonomy_uninstall() { - db_query('DROP TABLE {gmap_taxonomy_node}'); - db_query('DROP TABLE {gmap_taxonomy_term}'); + drupal_uninstall_schema('gmap_taxonomy'); +} + +/** + * Implementation of hook_schema(). + */ +function gmap_taxonomy_schema() { + $schema['gmap_taxonomy_term'] = array( + 'fields' => array( + 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'marker' => array('type' => 'varchar', 'length' => 32), + ), + 'primary key' => array('tid'), + ); + + $schema['gmap_taxonomy_node'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'marker' => array('type' => 'varchar', 'length' => 32), + ), + 'primary key' => array('vid'), + 'indexes' => array( + 'nid' => array('nid'), + ), + ); + + return $schema; } /** @@ -43,17 +55,12 @@ function gmap_taxonomy_uninstall() { function gmap_taxonomy_update_5001() { $ret = array(); // Add the new column. - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("ALTER TABLE {gmap_taxonomy_node} ADD tid int(10) unsigned NOT NULL default '0' AFTER vid"); - $ret[] = update_sql('TRUNCATE {gmap_taxonomy_node}'); - // Useful for repopulating in bulk... Copy to hook_enable()? - $ret[] = update_sql("INSERT INTO {gmap_taxonomy_node} (nid, vid, tid, marker) (SELECT n.nid, n.vid, t.tid, g.marker FROM {node_revisions} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {gmap_taxonomy_term} g ON t.tid = g.tid GROUP BY n.vid ORDER BY NULL)"); - break; - case 'pgsql': - // This update will never be needed for pgsql, as it predates pgsql support. - break; - } + // @@@ AFTER vid... + db_add_field($ret, 'gmap_taxonomy_node', 'tid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); + + // Useful for repopulating in bulk... Copy to hook_enable()? + $ret[] = update_sql('DELETE FROM {gmap_taxonomy_node}'); + $ret[] = update_sql("INSERT INTO {gmap_taxonomy_node} (nid, vid, tid, marker) (SELECT n.nid, n.vid, t.tid, g.marker FROM {node_revisions} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {gmap_taxonomy_term} g ON t.tid = g.tid GROUP BY n.vid ORDER BY NULL)"); + return $ret; } -- GitLab