diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-05-25 12:46:46 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-05-25 12:46:46 +0000 |
commit | 3cafffe63f70f418d0b6ca32ac5e0f3e27dceb41 (patch) | |
tree | cd59a40556a084f35b7b5a3bc3caa50874087541 | |
parent | ae762838c0e92bded86370103df4583874c50da7 (diff) | |
download | brdo-3cafffe63f70f418d0b6ca32ac5e0f3e27dceb41.tar.gz brdo-3cafffe63f70f418d0b6ca32ac5e0f3e27dceb41.tar.bz2 |
- Killer patch #144765 by bjaspan, frando et al: schema API 1 hits core. Oh, behave.
40 files changed, 2412 insertions, 1591 deletions
diff --git a/includes/common.inc b/includes/common.inc index feb28de30..fb7f21a41 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2514,6 +2514,160 @@ function drupal_common_themes() { } /** + * @ingroup schemaapi + * @{ + */ + +/** + * Get the schema defintion of a table, or the whole database schema. + * The returned schema will include any modifications made by any + * module that implements hook_schema_alter(). + * + * @param $name + * The name of the table. If not given, the schema of all tables is returned. + * @param $rebuild + * If true, the schema will be rebuilt instead of retreived from the cache. + */ +function drupal_get_schema($name = NULL, $rebuild = FALSE) { + static $schema = array(); + + if (empty($schema) || $rebuild) { + // Try to load the schema from cache. + if (!$rebuild && $cached = cache_get('schema')) { + $schema = $cached->data; + } + // Otherwise, rebuild the schema cache. + else { + // Load the .schema files. + module_load_all_includes('schema'); + + // Invoke hook_schema for all modules. + foreach (module_implements('schema') as $module) { + $current = module_invoke($module, 'schema'); + _drupal_initialize_schema($module, $current); + $schema = array_merge($current, $schema); + } + + drupal_alter('schema', $schema); + cache_set('schema', $schema); + } + } + + if (!isset($name)) { + return $schema; + } + elseif (isset($schema[$name])) { + return $schema[$name]; + } + else { + return FALSE; + } +} + +/** + * Create all tables that a module defines in its hook_schema(). + * + * Note: This function does not pass the module's schema through + * hook_schema_alter(). The module's tables will be created exactly + * as the module defines them. + * + * @param $module + * The module for which the tables will be created. + */ +function drupal_install_schema($module) { + $schema = drupal_get_schema_unprocessed($module); + _drupal_initialize_schema($module, $schema); + + $ret = array(); + foreach ($schema as $table) { + db_create_table($ret, $table); + } +} + +/** + * Remove all tables that a module defines in its hook_schema(). + * + * Note: This function does not pass the module's schema through + * hook_schema_alter(). The module's tables will be created exactly + * as the module defines them. + * + * @param $module + * The module for which the tables will be removed. + */ +function drupal_uninstall_schema($module) { + $schema = drupal_get_schema_unprocessed($module); + _drupal_initialize_schema($module, $schema); + + $ret = array(); + foreach ($schema as $table) { + db_drop_table($ret, $table['name']); + } +} + +/** + * Returns the unprocessed and unaltered version of a module's schema. + * + * Use this function only if you explicitly need the original + * specification of a schema, as it was defined in a module's + * hook_schema(). No additional default values will be set, + * hook_schema_alter() is not invoked and these unprocessed + * definitions won't be cached. + * + * This function can be used to retrieve a schema specification in + * hook_schema(), so it allows you to derive your tables from existing + * specifications. + * + * It is also used by drupal_install_schema() and + * drupal_uninstall_schema() to ensure that a module's tables are + * created exactly as specified without any changes introduced by a + * module that implements hook_schema_alter(). + * + * @param $module + * The module to which the table belongs. + * @param $table + * The name of the table. If not given, the module's complete schema + * is returned. + */ +function drupal_get_schema_unprocessed($module, $table = NULL) { + // Load the .schema file. + module_load_include('schema', $module); + $schema = module_invoke($module, 'schema'); + + if (!is_null($table) && isset($schema[$table])) { + return $schema[$table]; + } + else { + return $schema; + } +} + +/** + * Fill in required default values for table definitions returned by + * hook_schema(). + * + * @param $module + * The module for which hook_schema() was invoked. + * @param $schema + * The schema definition array as it was returned by the module's + * hook_schema(). + */ +function _drupal_initialize_schema($module, &$schema) { + // Set the name and module key for all tables. + foreach ($schema as $name => $table) { + if (empty($table['module'])) { + $schema[$name]['module'] = $module; + } + if (!isset($table['name'])) { + $schema[$name]['name'] = $name; + } + } +} + +/** + * @} End of "ingroup schemaapi". + */ + +/** * Parse Drupal info file format. * * Files should use an ini-like format to specify values. diff --git a/includes/database.inc b/includes/database.inc index 3e095e334..6e4bdeace 100644 --- a/includes/database.inc +++ b/includes/database.inc @@ -44,6 +44,22 @@ */ /** + * Perform an SQL query and return success or failure. + * + * @param $sql + * A string containing a complete SQL query. %-substitution + * parameters are not supported. + * @return + * An array containing the keys: + * success: a boolean indicating whether the query succeeded + * query: the SQL query executed, passed through check_plain() + */ +function update_sql($sql) { + $result = db_query($sql, true); + return array('success' => $result !== FALSE, 'query' => check_plain($sql)); +} + +/** * Append a database prefix to all tables in a query. * * Queries sent to Drupal should wrap all table names in curly brackets. This @@ -317,3 +333,144 @@ function db_escape_table($string) { * @} End of "defgroup database". */ +/** + * @defgroup schemaapi Schema API + * @{ + * + * A Drupal schema definition is an array structure representing one or + * more tables and their related keys and indexes. A schema is defined by + * hook_schema(), which usually lives in a modulename.schema file. + * + * By implenting hook_schema() and specifying the tables your module + * declares, you can easily create and drop these tables on all + * supported database engines. You don't have to deal with the + * different SQL dialects for table creation and alteration of the + * supported database engines. + * + * hook_schema() should return an array with a key for each table that + * the module defines. + * + * The following keys in the table definition are processed during + * table creation: + * + * - 'fields': An associative array ('fieldname' => specification) + * that describes the table's database columns. The specification + * is also an array. The following specification parameters are defined: + * + * - 'type': The generic datatype: 'varchar', 'int', 'serial' + * 'float', 'numeric', 'text', 'blob' or 'datetime'. Most types + * just map to the according database engine specific + * datatypes. Use 'serial' for auto incrementing fields. This + * will expand to 'int auto_increment' on mysql. + * - 'size': The data size: 'tiny', 'small', 'medium', 'normal', + * 'big'. This is a hint about the largest value the field will + * store and determines which of the database engine specific + * datatypes will be used (e.g. on MySQL, TINYINT vs. INT vs. BIGINT). + * 'normal', the default, selects the base type (e.g. on MySQL, + * INT, VARCHAR, BLOB, etc.). + * + * Not all sizes are available for all data types. See + * db_type_map() for possible combinations. + * - 'not null': If true, no NULL values will be allowed in this + * database column. Defaults to false. + * - 'default': The field's default value. The PHP type of the + * value matters: '', '0', and 0 are all different. If you + * specify '0' as the default value for a type 'int' field it + * will not work because '0' is a string containing the + * character "zero", not an integer. + * - 'length': The maximal length of a type 'varchar' or 'text' + * field. Ignored for other field types. + * - 'unsigned': A boolean indicating whether a type 'int', 'float' + * and 'numeric' only is signed or unsigned. Defaults to + * FALSE. Ignored for other field types. + * - 'precision', 'scale': For type 'numeric' fields, indicates + * the precision (total number of significant digits) and scale + * (decimal digits right of the decimal point). Both values are + * mandatory. Ignored for other field types. + * + * All parameters apart from 'type' are optional except that type + * 'numeric' columns must specify 'precision' and 'scale'. + * + * - 'primary key': An array of one or more key column specifers (see below) + * that form the primary key. + * - 'unique key': An associative array of unique keys ('keyname' => + * specification). Each specification is an array of one or more + * key column specifiers (see below) that form a unique key on the table. + * - 'indexes': An associative array of indexes ('indexame' => + * specification). Each specification is an array of one or more + * key column specifiers (see below) that form an index on the + * table. + * + * A key column specifier is either a string naming a column or an + * array of two elements, column name and length, specifying a prefix + * of the named column. + * + * As an example, here is a SUBSET of the schema definition for + * Drupal's 'node' table. It show four fields (nid, vid, type, and + * title), the primary key on field 'nid', a unique key named 'vid' on + * field 'vid', and two indexes, one named 'nid' on field 'nid' and + * one named 'node_title_type' on the field 'title' and the first four + * bytes of the field 'type': + * + * $schema['node'] = array( + * 'fields' => array( + * 'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + * 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + * 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + * ), + * 'primary key' => array('nid'), + * 'unique keys' => array( + * 'vid' => array('vid') + * ), + * 'indexes' => array( + * 'nid' => array('nid'), + * 'node_title_type' => array('title', array('type', 4)), + * ), + * ); + * + * @see drupal_install_schema() + */ + + /** + * Create a new table from a Drupal table definition. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * A valid and processed table schema definition array. + */ +function db_create_table(&$ret, $table) { + $statements = db_create_table_sql($table); + foreach ($statements as $statement) { + $ret[] = update_sql($statement); + } +} + +/** + * Return an array of field names from an array of key/index column + * specifiers. This is usually an identity function but if a + * key/index uses a column prefix specification, this function + * extracts just the name. + * + * @param $fields + * An array of key/index column specifiers. + * @return + * An array of field names. + */ +function db_field_names($fields) { + $ret = array(); + foreach ($fields as $field) { + if (is_array($field)) { + $ret[] = $field[0]; + } + else { + $ret[] = $field; + } + } + return $ret; +} + +/** + * @} End of "defgroup schemaapi". + */ diff --git a/includes/database.mysql-common.inc b/includes/database.mysql-common.inc new file mode 100644 index 000000000..c35c90d45 --- /dev/null +++ b/includes/database.mysql-common.inc @@ -0,0 +1,409 @@ +<?php + +// $Id$ + +/** + * @file + * Functions shared between mysql and mysqli database engines. + */ + +/** + * @ingroup schemaapi + * @{ + */ + +/** + * Generate SQL to create a new table from a Drupal schema definition. + * + * @param $table + * A valid Drupal table definition array. + * @return + * An array of SQL statements to create the table. + */ +function db_create_table_sql($table) { + + if (empty($table['mysql_suffix'])) { + $table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */"; + } + + $sql = "CREATE TABLE {". $table['name'] ."} (\n"; + + // Add the SQL statement for each field. + foreach ($table['fields'] as $name => $field) { + $sql .= _db_create_field_sql($name, _db_process_field($field)) .", \n"; + } + + // Process keys & indexes. + if (!empty($table['primary key'])) { + $sql .= " PRIMARY KEY (". _db_create_key_sql($table['primary key']) ."), \n"; + } + if (!empty($table['unique keys'])) { + foreach ($table['unique keys'] as $key => $fields) + $sql .= " UNIQUE KEY $key (". _db_create_key_sql($fields) ."), \n"; + } + if (!empty($table['indexes'])) { + foreach ($table['indexes'] as $index => $fields) + $sql .= " INDEX $index (". _db_create_key_sql($fields) ."), \n"; + } + + // Remove the last comma and space. + $sql = substr($sql, 0, -3) ."\n) "; + + $sql .= $table['mysql_suffix']; + + return array($sql); +} + +function _db_create_key_sql($fields) { + $ret = array(); + foreach ($fields as $field) { + if (is_array($field)) { + $ret[] = $field[0] .'('. $field[1] .')'; + } + else { + $ret[] = $field; + } + } + return implode(', ', $ret); +} + +/** + * Set database-engine specific properties for a field. + * + * @param $field + * A field description array, as specified in the schema documentation. + */ +function _db_process_field($field) { + + if (!isset($field['size'])) { + $field['size'] = 'normal'; + } + + // Set the correct database-engine specific datatype. + if (!isset($field['mysql_type'])) { + $map = db_type_map(); + $field['mysql_type'] = $map[$field['type'] .':'. $field['size']]; + } + + if ($field['type'] == 'serial') { + $field['auto_increment'] = TRUE; + } + + return $field; +} + +/** + * Create an SQL string for a field to be used in table creation or alteration. + * + * Before passing a field out of a schema definition into this function it has + * to be processed by _db_process_field(). + * + * @param $name + * Name of the field. + * @param $spec + * The field specification, as per the schema data structure format. + */ +function _db_create_field_sql($name, $spec) { + $sql = "`". $name ."` ". $spec['mysql_type']; + + if (isset($spec['length'])) { + $sql .= '('. $spec['length'] .')'; + } + elseif (isset($spec['precision']) && isset($spec['scale'])) { + $sql .= '('. $spec['scale'] .', '. $spec['precision'] .')'; + } + + if (!empty($spec['unsigned'])) { + $sql .= ' unsigned'; + } + + if (!empty($spec['not null'])) { + $sql .= ' NOT NULL'; + } + + if (!empty($spec['auto_increment'])) { + $sql .= ' auto_increment'; + } + + if (isset($spec['default'])) { + if (is_string($spec['default'])) { + $spec['default'] = "'". $spec['default'] ."'"; + } + $sql .= ' DEFAULT '. $spec['default']; + } + + if (empty($spec['not null']) && !isset($spec['default'])) { + $sql .= ' DEFAULT NULL'; + } + + return $sql; +} + +/** + * This maps a generic data type in combination with its data size + * to the engine-specific data type. + */ +function db_type_map() { + // Put :normal last so it gets preserved by array_flip. This makes + // it much easier for modules (such as schema.module) to map + // database types back into schema types. + $map = array( + 'varchar:normal' => 'VARCHAR', + + 'text:tiny' => 'SMALLTEXT', + 'text:small' => 'SMALLTEXT', + 'text:medium' => 'MEDIUMTEXT', + 'text:big' => 'LONGTEXT', + 'text:normal' => 'TEXT', + + 'serial:tiny' => 'TINYINT', + 'serial:small' => 'SMALLINT', + 'serial:medium' => 'MEDIUMINT', + 'serial:big' => 'BIGINT', + 'serial:normal' => 'INT', + + 'int:tiny' => 'TINYINT', + 'int:small' => 'SMALLINT', + 'int:medium' => 'MEDIUMINT', + 'int:big' => 'BIGINT', + 'int:normal' => 'INT', + + 'float:tiny' => 'FLOAT', + 'float:small' => 'FLOAT', + 'float:medium' => 'FLOAT', + 'float:big' => 'DOUBLE', + 'float:normal' => 'FLOAT', + + 'numeric:normal' => 'NUMERIC', + + 'blob:big' => 'LONGBLOB', + 'blob:normal' => 'BLOB', + + 'datetime:normal' => 'DATETIME', + ); + return $map; +} + +/** + * Drop a table. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be dropped. + */ +function db_drop_table(&$ret, $table) { + $ret[] = update_sql('DROP TABLE {'. $table .'}'); +} + +/** + * Add a new field to a table. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * Name of the table to be altered. + * @param $field + * Name of the field to be added. + * @param $spec + * The field specification array, as taken from a schema definition + */ +function db_add_field(&$ret, $table, $field, $spec) { + $query = 'ALTER TABLE {'. $table .'} ADD '. $field .' '; + $query .= _db_create_field_sql($field, _db_process_field($spec)); + $ret[] = update_sql($query); +} + +/** + * Drop a field. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $field + * The field to be dropped. + */ +function db_drop_field(&$ret, $table, $field) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP '. $field); +} + +/** + * Set the default value for a field. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $field + * The field to be altered. + * @param $default + * Default value to be set. NULL for 'default NULL'. + */ +function db_field_set_default(&$ret, $table, $field, $default) { + if ($default == NULL) { + $default = 'NULL'; + } + else { + $default = is_string($default) ? "'$default'" : $default; + } + + $ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' SET DEFAULT '. $default); +} + +/** + * Set a field to have no default value. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $field + * The field to be altered. + */ +function db_field_set_no_default(&$ret, $table, $field) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' DROP DEFAULT'); +} + +/** + * Add a primary key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $fields + * Fields for the primary key. + */ +function db_add_primary_key(&$ret, $table, $fields) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} ADD PRIMARY KEY ('. + _db_create_key_sql($fields) .')'); +} + +/** + * Drop the primary key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + */ +function db_drop_primary_key(&$ret, $table) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP PRIMARY KEY'); +} + +/** + * Add a unique key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the key. + * @param $fields + * An array of field names. + */ +function db_add_unique_key(&$ret, $table, $name, $fields) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} ADD UNIQUE KEY '. + $name .' ('. _db_create_key_sql($fields) .')'); +} + +/** + * Drop a unique key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the key. + */ +function db_drop_unique_key(&$ret, $table, $name) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP KEY '. $name); +} + +/** + * Add an index. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the index. + * @param $fields + * An array of field names. + */ +function db_add_index(&$ret, $table, $name, $fields) { + $query = 'ALTER TABLE {'. $table .'} ADD INDEX '. $name .' ('; + + foreach ($fields as $current) { + $query .= $current .', '; + } + + // Remove the last comma, add a closing bracket. + $query = substr($query, 0, -2) .')'; + + $ret[] = update_sql($query); +} + +/** + * Drop an index. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the index. + */ +function db_drop_index(&$ret, $table, $name) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP INDEX '. $name); +} + +/** + * Change a field definition. + * + * Remember that changing a field definition involves adding a new field + * and dropping an old one. This means that any indices, primary keys and + * sequences from serial-type fields are dropped and might need to be + * recreated. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * Name of the table. + * @param $field + * Name of the field to change. + * @param $field_new + * New name for the field (set to the same as $field if you don't want to change the name). + * @param $spec + * The field specification for the new field. + */ +function db_change_field(&$ret, $table, $field, $field_new, $spec) { + $ret[] = update_sql("ALTER TABLE {". $table ."} CHANGE $field ". + _db_create_field_sql($field_new, _db_process_field($spec))); +} + +/** + * Update a field definition to match its schema. If the field is + * involved in any keys or indexes, recreate them. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * Name of the table. + * @param $field + * Name of the field to update. + */ +function db_update_field(&$ret, $table, $field) { + $spec = drupal_get_schema($table); + db_change_field($ret, $table, $field, $field, $spec['fields'][$field]); +} + +/** + * @} End of "ingroup schemaapi". + */ + +?>
\ No newline at end of file diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 1fab19191..166017621 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -11,6 +11,8 @@ * @{ */ +// Include functions shared between mysql and mysqli. +require_once './includes/database.mysql-common.inc'; /** * Report database status. @@ -437,5 +439,3 @@ function db_distinct_field($table, $field, $query) { /** * @} End of "ingroup database". */ - - diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc index 04f8cc9aa..ad58a6f24 100644 --- a/includes/database.mysqli.inc +++ b/includes/database.mysqli.inc @@ -15,6 +15,9 @@ * @{ */ +// Include functions shared between mysql and mysqli. +require_once './includes/database.mysql-common.inc'; + /** * Report database status. */ diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index be5e4447a..3e050d8d1 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -436,4 +436,422 @@ function db_distinct_field($table, $field, $query) { * @} End of "ingroup database". */ +/** + * @ingroup schemaapi + * @{ + */ + +/** + * This maps a generic data type in combination with its data size + * to the engine-specific data type. + */ +function db_type_map() { + // Put :normal last so it gets preserved by array_flip. This makes + // it much easier for modules (such as schema.module) to map + // database types back into schema types. + $map = array( + 'varchar:normal' => 'varchar', + + 'text:tiny' => 'text', + 'text:small' => 'text', + 'text:medium' => 'text', + 'text:big' => 'text', + 'text:normal' => 'text', + + 'int:tiny' => 'smallint', + 'int:small' => 'smallint', + 'int:medium' => 'int', + 'int:big' => 'bigint', + 'int:normal' => 'int', + + 'float:tiny' => 'real', + 'float:small' => 'real', + 'float:medium' => 'real', + 'float:big' => 'double precision', + 'float:normal' => 'real', + + 'numeric:normal' => 'numeric', + + 'blob:big' => 'bytea', + 'blob:normal' => 'bytea', + + 'datetime:normal' => 'timestamp', + + 'serial:tiny' => 'serial', + 'serial:small' => 'serial', + 'serial:medium' => 'serial', + 'serial:big' => 'bigserial', + 'serial:normal' => 'serial', + ); + return $map; +} + +/** + * Generate SQL to create a new table from a Drupal schema definition. + * + * @param $table + * A valid Drupal table definition array. + * @return + * An array of SQL statements to create the table. + */ +function db_create_table_sql($table) { + $sql_fields = array(); + foreach ($table['fields'] as $name => $field) { + $sql_fields[] = _db_create_field_sql($name, _db_process_field($field)); + } + + $sql_keys = array(); + if (isset($table['primary key']) && is_array($table['primary key'])) { + $sql_keys[] = 'PRIMARY KEY ('. implode(', ', $table['primary key']) .')'; + } + if (isset($table['unique keys']) && is_array($table['unique keys'])) { + foreach ($table['unique keys'] as $keyname => $key) { + $sql_keys[] = 'CONSTRAINT {'. $table['name'] .'}_'. $keyname .'_key UNIQUE ('. implode(', ', $key) .')'; + } + } + + $sql = "CREATE TABLE {". $table['name'] ."} (\n\t"; + $sql .= implode(",\n\t", $sql_fields); + if (count($sql_keys) > 0) { + $sql .= ",\n\t"; + } + $sql .= implode(",\n\t", $sql_keys); + $sql .= "\n)"; + $statements[] = $sql; + + if (isset($table['indexes']) && is_array($table['indexes'])) { + foreach ($table['indexes'] as $keyname => $key) { + $statements[] = _db_create_index_sql($table['name'], $keyname, $key); + } + } + + return $statements; +} + +function _db_create_index_sql($table, $name, $fields) { + $query = 'CREATE INDEX {'. $table .'}_'. $name .'_idx ON {'. $table .'} ('; + $query .= _db_create_key_sql($fields) .')'; + return $query; +} + +function _db_create_key_sql($fields) { + $ret = array(); + foreach ($fields as $field) { + if (is_array($field)) { + $ret[] = 'substr('. $field[0] .', 1, '. $field[1] .')'; + } + else { + $ret[] = $field; + } + } + return implode(', ', $ret); +} + +/** + * Set database-engine specific properties for a field. + * + * @param $field + * A field description array, as specified in the schema documentation. + */ +function _db_process_field($field) { + if (!isset($field['size'])) { + $field['size'] = 'normal'; + } + // Set the correct database-engine specific datatype. + if (!isset($field['pgsql_type'])) { + $map = db_type_map(); + $field['pgsql_type'] = $map[$field['type'] .':'. $field['size']]; + } + if ($field['type'] == 'serial') { + unset($field['not null']); + } + return $field; +} + +/** + * Create an SQL string for a field to be used in table creation or alteration. + * + * Before passing a field out of a schema definition into this function it has + * to be processed by _db_process_field(). + * + * @param $name + * Name of the field. + * @param $spec + * The field specification, as per the schema data structure format. + */ +function _db_create_field_sql($name, $spec) { + $sql = $name .' '. $spec['pgsql_type']; + + if ($spec['type'] == 'serial') { + unset($spec['not null']); + } + if (!empty($spec['unsigned'])) { + if ($spec['type'] == 'serial') { + $sql .= " CHECK ($name >= 0)"; + } + else { + $sql .= '_unsigned'; + } + } + + if (!empty($spec['length'])) { + $sql .= '('. $spec['length'] .')'; + } + elseif (isset($spec['precision']) && isset($spec['scale'])) { + $sql .= '('. $spec['scale'] .', '. $spec['precision'] .')'; + } + + if (isset($spec['not null']) && $spec['not null']) { + $sql .= ' NOT NULL'; + } + if (isset($spec['default'])) { + $default = is_string($spec['default']) ? "'". $spec['default'] ."'" : $spec['default']; + $sql .= " default $default"; + } + + return $sql; +} + +/** + * Drop a table. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be dropped. + */ +function db_drop_table(&$ret, $table) { + $ret[] = update_sql('DROP TABLE {'. $table .'}'); +} + +/** + * Add a new field to a table. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * Name of the table to be altered. + * @param $field + * Name of the field to be added. + * @param $spec + * The field specification array, as taken from a schema definition + */ +function db_add_field(&$ret, $table, $field, $spec) { + $query = 'ALTER TABLE {'. $table .'} ADD COLUMN '; + $query .= _db_create_field_sql($field, _db_process_field($spec)); + $ret[] = update_sql($query); +} + +/** + * Drop a field. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $field + * The field to be dropped. + */ +function db_drop_field(&$ret, $table, $field) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP COLUMN '. $field); +} + +/** + * Set the default value for a field. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $field + * The field to be altered. + * @param $default + * Default value to be set. NULL for 'default NULL'. + */ +function db_field_set_default(&$ret, $table, $field, $default) { + if ($default == NULL) { + $default = 'NULL'; + } + else { + $default = is_string($default) ? "'$default'" : $default; + } + + $ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' SET DEFAULT '. $default); +} + +/** + * Set a field to have no default value. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $field + * The field to be altered. + */ +function db_field_set_no_default(&$ret, $table, $field) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' DROP DEFAULT'); +} + +/** + * Add a primary key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $fields + * Fields for the primary key. + */ +function db_add_primary_key(&$ret, $table, $fields) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} ADD PRIMARY KEY ('. + implode(',', $fields) .')'); +} + +/** + * Drop the primary key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + */ +function db_drop_primary_key(&$ret, $table) { + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT {'. $table .'}_pkey'); +} + +/** + * Add a unique key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the key. + * @param $fields + * An array of field names. + */ +function db_add_unique_key(&$ret, $table, $name, $fields) { + $name = '{'. $table .'}_'. $name .'_key'; + $ret[] = update_sql('ALTER TABLE {'. $table .'} ADD CONSTRAINT '. + $name .' UNIQUE ('. implode(',', $fields) .')'); +} + +/** + * Drop a unique key. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the key. + */ +function db_drop_unique_key(&$ret, $table, $name) { + $name = '{'. $table .'}_'. $name .'_key'; + $ret[] = update_sql('ALTER TABLE {'. $table .'} DROP CONSTRAINT '. $name); +} + +/** + * Add an index. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the index. + * @param $fields + * An array of field names. + */ +function db_add_index(&$ret, $table, $name, $fields) { + $ret[] = update_sql(_db_create_index_sql($table, $name, $fields)); +} + +/** + * Drop an index. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * The table to be altered. + * @param $name + * The name of the index. + */ +function db_drop_index(&$ret, $table, $name) { + $name = '{'. $table .'}_'. $name .'_idx'; + $ret[] = update_sql('DROP INDEX '. $name); +} + +/** + * Change a field definition. + * + * Remember that changing a field definition involves adding a new field + * and dropping an old one. This means that any indices, primary keys and + * sequences from serial-type fields are dropped and might need to be + * recreated. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * Name of the table. + * @param $field + * Name of the field to change. + * @param $field_new + * New name for the field (set to the same as $field if you don't want to change the name). + * @param $spec + * The field specification for the new field. + */ +function db_change_field(&$ret, $table, $field, $field_new, $spec) { + $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $field TO ". $field ."_old"); + $not_null = isset($spec['not null']) ? $spec['not null'] : FALSE; + unset($spec['not null']); + db_add_field($ret, $table, "$field_new", $spec); + $ret[] = update_sql("UPDATE {". $table ."} SET $field_new = ". $field ."_old"); + if ($not_null) { + $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $field_new SET NOT NULL"); + } + db_drop_field($ret, $table, $field .'_old'); +} + +/** + * Update a field definition to match its schema. If the field is + * involved in any keys or indexes, recreate them if necessary. + * + * @param $ret + * Array to which query results will be added. + * @param $table + * Name of the table. + * @param $field + * Name of the field to update. + */ +function db_update_field(&$ret, $table, $field) { + $spec = drupal_get_schema($table); + + db_change_field($ret, $table, $field, $field, $spec['fields'][$field]); + if (isset($spec['primary key'])) { + if (array_search($field, db_field_names($spec['primary key'])) !== FALSE) { + db_add_primary_key($ret, $table, $spec['primary key']); + } + } + if (isset($spec['unique keys'])) { + foreach ($spec['unique keys'] as $name => $fields) { + if (array_search($field, db_field_names($fields)) !== FALSE) { + db_add_unique_key($ret, $table, $fields); + } + } + } + if (isset($spec['indexes'])) { + foreach ($spec['indexes'] as $name => $fields) { + if (array_search($field, db_field_names($fields)) !== FALSE) { + db_add_index($ret, $table, $fields); + } + } + } +} + +/** + * @} End of "ingroup schemaapi". + */ diff --git a/includes/module.inc b/includes/module.inc index 5ff8f5575..dcec75f5c 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -189,9 +189,42 @@ function module_load_install($module) { // Make sure the installation API is available include_once './includes/install.inc'; - $install_file = './'. drupal_get_path('module', $module) .'/'. $module .'.install'; - if (is_file($install_file)) { - include_once $install_file; + module_load_include('install', $module); +} + +/** + * Load a module include file. + * + * @param $type + * The include file's type (file extension). + * @param $module + * The module to which the include file belongs. + * @param $name + * Optionally, specify the file name. If not set, the module's name is used. + */ +function module_load_include($type, $module, $name = NULL) { + if (empty($name)) { + $name = $module; + } + + $file = './'. drupal_get_path('module', $module) ."/$name.$type"; + + if (is_file($file)) { + require_once $file; + } + else { + return FALSE; + } +} + +/** + * Load an include file for each of the modules that have been enabled in + * the system table. + */ +function module_load_all_includes($type, $name = NULL) { + $modules = module_list(); + foreach ($modules as $module) { + module_load_include($type, $module, $name); } } diff --git a/modules/aggregator/aggregator.install b/modules/aggregator/aggregator.install index 9cc59cc2d..8c44c33a7 100644 --- a/modules/aggregator/aggregator.install +++ b/modules/aggregator/aggregator.install @@ -5,126 +5,17 @@ * Implementation of hook_install(). */ function aggregator_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {aggregator_category} ( - cid int NOT NULL auto_increment, - title varchar(255) NOT NULL default '', - description longtext NOT NULL, - block tinyint NOT NULL default '0', - PRIMARY KEY (cid), - UNIQUE KEY title (title) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {aggregator_category_feed} ( - fid int NOT NULL default '0', - cid int NOT NULL default '0', - PRIMARY KEY (fid,cid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {aggregator_category_item} ( - iid int NOT NULL default '0', - cid int NOT NULL default '0', - PRIMARY KEY (iid,cid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {aggregator_feed} ( - fid int NOT NULL auto_increment, - title varchar(255) NOT NULL default '', - url varchar(255) NOT NULL default '', - refresh int NOT NULL default '0', - checked int NOT NULL default '0', - link varchar(255) NOT NULL default '', - description longtext NOT NULL, - image longtext NOT NULL, - etag varchar(255) NOT NULL default '', - modified int NOT NULL default '0', - block tinyint NOT NULL default '0', - PRIMARY KEY (fid), - UNIQUE KEY link (url), - UNIQUE KEY title (title) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {aggregator_item} ( - iid int NOT NULL auto_increment, - fid int NOT NULL default '0', - title varchar(255) NOT NULL default '', - link varchar(255) NOT NULL default '', - author varchar(255) NOT NULL default '', - description longtext NOT NULL, - timestamp int default NULL, - guid varchar(255), - PRIMARY KEY (iid), - KEY fid (fid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - break; - case 'pgsql': - db_query("CREATE TABLE {aggregator_category} ( - cid serial, - title varchar(255) NOT NULL default '', - description text NOT NULL, - block smallint NOT NULL default '0', - PRIMARY KEY (cid), - UNIQUE (title) - )"); - - db_query("CREATE TABLE {aggregator_category_feed} ( - fid int NOT NULL default '0', - cid int NOT NULL default '0', - PRIMARY KEY (fid,cid) - )"); - - db_query("CREATE TABLE {aggregator_category_item} ( - iid int NOT NULL default '0', - cid int NOT NULL default '0', - PRIMARY KEY (iid,cid) - )"); - - db_query("CREATE TABLE {aggregator_feed} ( - fid serial, - title varchar(255) NOT NULL default '', - url varchar(255) NOT NULL default '', - refresh int NOT NULL default '0', - checked int NOT NULL default '0', - link varchar(255) NOT NULL default '', - description text NOT NULL default '', - image text NOT NULL default '', - etag varchar(255) NOT NULL default '', - modified int NOT NULL default '0', - block smallint NOT NULL default '0', - PRIMARY KEY (fid), - UNIQUE (url), - UNIQUE (title) - )"); - - db_query("CREATE TABLE {aggregator_item} ( - iid serial, - fid int NOT NULL default '0', - title varchar(255) NOT NULL default '', - link varchar(255) NOT NULL default '', - author varchar(255) NOT NULL default '', - description text NOT NULL, - timestamp int default NULL, - guid varchar(255), - PRIMARY KEY (iid) - )"); - db_query("CREATE INDEX {aggregator_item}_fid_idx ON {aggregator_item} (fid)"); - - break; - } + // Create tables. + drupal_install_schema('aggregator'); } /** * Implementation of hook_uninstall(). */ function aggregator_uninstall() { - db_query('DROP TABLE {aggregator_category}'); - db_query('DROP TABLE {aggregator_category_feed}'); - db_query('DROP TABLE {aggregator_category_item}'); - db_query('DROP TABLE {aggregator_feed}'); - db_query('DROP TABLE {aggregator_item}'); + // Remove tables. + drupal_uninstall_schema('aggregator'); + variable_del('aggregator_allowed_html_tags'); variable_del('aggregator_summary_items'); variable_del('aggregator_clear'); diff --git a/modules/aggregator/aggregator.schema b/modules/aggregator/aggregator.schema new file mode 100644 index 000000000..ed0c146e9 --- /dev/null +++ b/modules/aggregator/aggregator.schema @@ -0,0 +1,70 @@ +<?php +// $Id$ + +function aggregator_schema() { + $schema['aggregator_category'] = array( + 'fields' => array( + 'cid' => array('type' => 'serial', 'not null' => TRUE), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'block' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array('cid'), + 'unique keys' => array('title' => array('title')), + ); + + $schema['aggregator_category_feed'] = array( + 'fields' => array( + 'fid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'cid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('fid', 'cid'), + ); + + $schema['aggregator_category_item'] = array( + 'fields' => array( + 'iid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'cid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('iid', 'cid'), + ); + + $schema['aggregator_feed'] = array( + 'fields' => array( + 'fid' => array('type' => 'serial', 'not null' => TRUE), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'url' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'refresh' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'checked' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'link' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'image' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'etag' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'modified' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'block' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'unique keys' => array( + 'url' => array('url'), + 'title' => array('title') + ), + 'primary key' => array('fid'), + ); + + $schema['aggregator_item'] = array( + 'fields' => array( + 'iid' => array('type' => 'serial', 'not null' => TRUE), + 'fid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'link' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'author' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'timestamp' => array('type' => 'int', 'not null' => FALSE), + 'guid' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE) + ), + 'indexes' => array('fid' => array('fid')), + 'primary key' => array('iid'), + ); + + return $schema; +} + diff --git a/modules/block/block.schema b/modules/block/block.schema new file mode 100644 index 000000000..2aca16075 --- /dev/null +++ b/modules/block/block.schema @@ -0,0 +1,49 @@ +<?php +// $Id$ + +function block_schema() { + $schema['blocks'] = array( + 'fields' => array( + 'bid' => array('type' => 'serial', 'not null' => TRUE), + 'module' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'delta' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '0'), + 'theme' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'region' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'left'), + 'custom' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'throttle' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'visibility' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'pages' => array('type' => 'text', 'not null' => TRUE), + 'title' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => '') + ), + 'primary key' => array('bid'), + ); + + $schema['blocks_roles'] = array( + 'fields' => array( + 'module' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), + 'delta' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE), + 'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE) + ), + 'primary key' => array( + 'module', + 'delta', + 'rid' + ), + ); + + $schema['boxes'] = array( + 'fields' => array( + 'bid' => array('type' => 'serial', 'not null' => TRUE), + 'body' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big'), + 'info' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'format' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0) + ), + 'unique keys' => array('info' => array('info')), + 'primary key' => array('bid'), + ); + + return $schema; +} + diff --git a/modules/book/book.install b/modules/book/book.install index 1051d5325..689225255 100644 --- a/modules/book/book.install +++ b/modules/book/book.install @@ -5,36 +5,14 @@ * Implementation of hook_install(). */ function book_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {book} ( - vid int unsigned NOT NULL default '0', - nid int unsigned NOT NULL default '0', - parent int NOT NULL default '0', - weight tinyint NOT NULL default '0', - PRIMARY KEY (vid), - KEY nid (nid), - KEY parent (parent) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {book} ( - vid int_unsigned NOT NULL default '0', - nid int_unsigned NOT NULL default '0', - parent int NOT NULL default '0', - weight smallint NOT NULL default '0', - PRIMARY KEY (vid) - )"); - db_query("CREATE INDEX {book}_nid_idx ON {book} (nid)"); - db_query("CREATE INDEX {book}_parent_idx ON {book} (parent)"); - break; - } + // Create tables. + drupal_install_schema('book'); } /** * Implementation of hook_uninstall(). */ function book_uninstall() { - db_query('DROP TABLE {book}'); + // Remove tables. + drupal_uninstall_schema('book'); } diff --git a/modules/book/book.schema b/modules/book/book.schema new file mode 100644 index 000000000..be3c54067 --- /dev/null +++ b/modules/book/book.schema @@ -0,0 +1,21 @@ +<?php +// $Id$ + +function book_schema() { + $schema['book'] = array( + 'fields' => array( + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'parent' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'indexes' => array( + 'nid' => array('nid'), + 'parent' => array('parent') + ), + 'primary key' => array('vid'), + ); + + return $schema; +} + diff --git a/modules/comment/comment.schema b/modules/comment/comment.schema new file mode 100644 index 000000000..5620aa1e7 --- /dev/null +++ b/modules/comment/comment.schema @@ -0,0 +1,45 @@ +<?php +// $Id$ + +function comment_schema() { + $schema['comments'] = array( + 'fields' => array( + 'cid' => array('type' => 'serial', 'not null' => TRUE), + 'pid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'subject' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'comment' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'score' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'medium'), + 'status' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'format' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0), + 'thread' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE), + 'users' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big'), + 'name' => array('type' => 'varchar', 'length' => 60, 'not null' => FALSE), + 'mail' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE), + 'homepage' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE) + ), + 'indexes' => array( + 'nid' => array('nid'), + 'status' => array('status') + ), + 'primary key' => array('cid'), + ); + + $schema['node_comment_statistics'] = array( + 'fields' => array( + 'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'last_comment_timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'last_comment_name' => array('type' => 'varchar', 'length' => 60, 'not null' => FALSE), + 'last_comment_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'comment_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array('node_comment_timestamp' => array('last_comment_timestamp')), + 'primary key' => array('nid'), + ); + + return $schema; +} + diff --git a/modules/contact/contact.install b/modules/contact/contact.install index b24c4ca51..fe31ca327 100644 --- a/modules/contact/contact.install +++ b/modules/contact/contact.install @@ -5,40 +5,17 @@ * Implementation of hook_install(). */ function contact_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {contact} ( - cid int unsigned NOT NULL auto_increment, - category varchar(255) NOT NULL default '', - recipients longtext NOT NULL, - reply longtext NOT NULL, - weight tinyint NOT NULL default '0', - selected tinyint NOT NULL default '0', - PRIMARY KEY (cid), - UNIQUE KEY category (category) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {contact} ( - cid serial CHECK (cid >= 0), - category varchar(255) NOT NULL default '', - recipients text NOT NULL default '', - reply text NOT NULL default '', - weight smallint NOT NULL default '0', - selected smallint NOT NULL default '0', - PRIMARY KEY (cid), - UNIQUE (category) - )"); - break; - } + // Create tables. + drupal_install_schema('contact'); } /** * Implementation of hook_uninstall(). */ function contact_uninstall() { - db_query('DROP TABLE {contact}'); + // Remove tables. + drupal_uninstall_schema('contact'); + variable_del('contact_default_status'); variable_del('contact_form_information'); variable_del('contact_hourly_threshold'); diff --git a/modules/contact/contact.schema b/modules/contact/contact.schema new file mode 100644 index 000000000..f77f6a27c --- /dev/null +++ b/modules/contact/contact.schema @@ -0,0 +1,20 @@ +<?php +// $Id$ + +function contact_schema() { + $schema['contact'] = array( + 'fields' => array( + 'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'category' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'recipients' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'reply' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'selected' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'unique keys' => array('category' => array('category')), + 'primary key' => array('cid'), + ); + + return $schema; +} + diff --git a/modules/dblog/dblog.install b/modules/dblog/dblog.install index 44961f7b1..b2f0ac97a 100644 --- a/modules/dblog/dblog.install +++ b/modules/dblog/dblog.install @@ -5,51 +5,14 @@ * Implementation of hook_install(). */ function dblog_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {watchdog} ( - wid int NOT NULL auto_increment, - uid int NOT NULL default '0', - type varchar(16) NOT NULL default '', - message longtext NOT NULL, - variables longtext NOT NULL, - severity tinyint unsigned NOT NULL default '0', - link varchar(255) NOT NULL default '', - location text NOT NULL, - referer varchar(128) NOT NULL default '', - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - PRIMARY KEY (wid), - KEY (type) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - - case 'pgsql': - db_query("CREATE TABLE {watchdog} ( - wid serial, - uid int NOT NULL default '0', - type varchar(16) NOT NULL default '', - message text NOT NULL, - variables text NOT NULL, - severity smallint_unsigned NOT NULL default '0', - link varchar(255) NOT NULL default '', - location text NOT NULL default '', - referer varchar(128) NOT NULL default '', - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - PRIMARY KEY (wid) - )"); - db_query("CREATE INDEX {watchdog}_type_idx ON {watchdog} (type)"); - - - break; - } + // Create tables. + drupal_install_schema('dblog'); } /** * Implementation of hook_uninstall(). */ function dblog_uninstall() { - db_query('DROP TABLE {watchdog}'); + // Remove tables. + drupal_uninstall_schema('dblog'); } diff --git a/modules/dblog/dblog.schema b/modules/dblog/dblog.schema new file mode 100644 index 000000000..785f1d98f --- /dev/null +++ b/modules/dblog/dblog.schema @@ -0,0 +1,25 @@ +<?php +// $Id$ + +function dblog_schema() { + $schema['watchdog'] = array( + 'fields' => array( + 'wid' => array('type' => 'serial', 'not null' => TRUE), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'type' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''), + 'message' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'variables' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'severity' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'link' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'location' => array('type' => 'text', 'not null' => TRUE), + 'referer' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('wid'), + 'indexes' => array('type' => array('type')), + ); + + return $schema; +} + diff --git a/modules/drupal/drupal.install b/modules/drupal/drupal.install index 909c539de..137b7d013 100644 --- a/modules/drupal/drupal.install +++ b/modules/drupal/drupal.install @@ -5,63 +5,17 @@ * Implementation of hook_install(). */ function drupal_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {client} ( - cid int unsigned NOT NULL auto_increment, - link varchar(255) NOT NULL default '', - name varchar(128) NOT NULL default '', - mail varchar(128) NOT NULL default '', - slogan longtext NOT NULL, - mission longtext NOT NULL, - users int NOT NULL default '0', - nodes int NOT NULL default '0', - version varchar(35) NOT NULL default'', - created int NOT NULL default '0', - changed int NOT NULL default '0', - PRIMARY KEY (cid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {client_system} ( - cid int NOT NULL default '0', - name varchar(255) NOT NULL default '', - type varchar(255) NOT NULL default '', - PRIMARY KEY (cid,name) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {client} ( - cid serial CHECK (cid >= 0), - link varchar(255) NOT NULL default '', - name varchar(128) NOT NULL default '', - mail varchar(128) NOT NULL default '', - slogan text NOT NULL, - mission text NOT NULL, - users int NOT NULL default '0', - nodes int NOT NULL default '0', - version varchar(35) NOT NULL default'', - created int NOT NULL default '0', - changed int NOT NULL default '0', - PRIMARY KEY (cid) - )"); - - db_query("CREATE TABLE {client_system} ( - cid int NOT NULL default '0', - name varchar(255) NOT NULL default '', - type varchar(255) NOT NULL default '', - PRIMARY KEY (cid,name) - )"); - break; - } + // Create tables. + drupal_install_schema('drupal'); } /** * Implementation of hook_uninstall(). */ function drupal_uninstall() { - db_query('DROP TABLE {client}'); - db_query('DROP TABLE {client_system}'); + // Remove tables. + drupal_uninstall_schema('drupal'); + variable_del('drupal_authentication_service'); variable_del('drupal_directory'); variable_del('drupal_register'); diff --git a/modules/drupal/drupal.schema b/modules/drupal/drupal.schema new file mode 100644 index 000000000..82b14d3ef --- /dev/null +++ b/modules/drupal/drupal.schema @@ -0,0 +1,33 @@ +<?php +// $Id$ + +function drupal_schema() { + $schema['client'] = array( + 'fields' => array( + 'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'link' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'mail' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'slogan' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'mission' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'users' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'nodes' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'version' => array('type' => 'varchar', 'length' => 35, 'not null' => TRUE, 'default' => ''), + 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'changed' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('cid'), + ); + + $schema['client_system'] = array( + 'fields' => array( + 'cid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'type' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '') + ), + 'primary key' => array('cid', 'name'), + ); + + return $schema; +} + diff --git a/modules/filter/filter.schema b/modules/filter/filter.schema new file mode 100644 index 000000000..fbdf8536e --- /dev/null +++ b/modules/filter/filter.schema @@ -0,0 +1,31 @@ +<?php +// $Id$ + +function filter_schema() { + $schema['filters'] = array( + 'fields' => array( + 'fid' => array('type' => 'serial', 'not null' => TRUE), + 'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'module' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'delta' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array('fid'), + 'indexes' => array('weight' => array('weight')), + ); + $schema['filter_formats'] = array( + 'fields' => array( + 'format' => array('type' => 'serial', 'not null' => TRUE), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'roles' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'cache' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'unique keys' => array('name' => array('name')), + 'primary key' => array('format'), + ); + + $schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache'); + + return $schema; +} + diff --git a/modules/forum/forum.install b/modules/forum/forum.install index 31ad02fa3..1c8d17b74 100644 --- a/modules/forum/forum.install +++ b/modules/forum/forum.install @@ -5,36 +5,17 @@ * Implementation of hook_install(). */ function forum_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {forum} ( - nid int unsigned NOT NULL default '0', - vid int unsigned NOT NULL default '0', - tid int unsigned NOT NULL default '0', - PRIMARY KEY (vid), - KEY nid (nid), - KEY tid (tid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {forum} ( - nid int_unsigned NOT NULL default '0', - vid int_unsigned NOT NULL default '0', - tid int_unsigned NOT NULL default '0', - PRIMARY KEY (vid) - )"); - db_query("CREATE INDEX {forum}_nid_idx ON {forum} (nid)"); - db_query("CREATE INDEX {forum}_tid_idx ON {forum} (tid)"); - break; - } + // Create tables. + drupal_install_schema('forum'); } /** * Implementation of hook_uninstall(). */ function forum_uninstall() { - db_query('DROP TABLE {forum}'); + // Remove tables. + drupal_uninstall_schema('forum'); + db_query("DELETE FROM {node} WHERE type = 'forum'"); variable_del('forum_containers'); variable_del('forum_nav_vocabulary'); diff --git a/modules/forum/forum.schema b/modules/forum/forum.schema new file mode 100644 index 000000000..56a7d688f --- /dev/null +++ b/modules/forum/forum.schema @@ -0,0 +1,20 @@ +<?php +// $Id$ + +function forum_schema() { + $schema['forum'] = 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) + ), + 'indexes' => array( + 'nid' => array('nid'), + 'tid' => array('tid') + ), + 'primary key' => array('vid'), + ); + + return $schema; +} + diff --git a/modules/locale/locale.install b/modules/locale/locale.install index 6c26e6c7c..b2c4f85e1 100644 --- a/modules/locale/locale.install +++ b/modules/locale/locale.install @@ -8,82 +8,10 @@ function locale_install() { // locales_source.source and locales_target.target are not used as binary // fields; non-MySQL database servers need to ensure the field type is text // and that LIKE produces a case-sensitive comparison. - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {languages} ( - language varchar(12) NOT NULL default '', - name varchar(64) NOT NULL default '', - native varchar(64) NOT NULL default '', - direction int NOT NULL default '0', - enabled int NOT NULL default '0', - plurals int NOT NULL default '0', - formula varchar(128) NOT NULL default '', - domain varchar(128) NOT NULL default '', - prefix varchar(128) NOT NULL default '', - weight int NOT NULL default '0', - PRIMARY KEY (language) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {locales_source} ( - lid int NOT NULL auto_increment, - location varchar(255) NOT NULL default '', - textgroup varchar(255) NOT NULL default '', - source blob NOT NULL, - PRIMARY KEY (lid), - KEY source (source(30)) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {locales_target} ( - lid int NOT NULL default '0', - translation blob NOT NULL, - language varchar(12) NOT NULL default '', - plid int NOT NULL default '0', - plural int NOT NULL default '0', - KEY lid (lid), - KEY lang (language), - KEY plid (plid), - KEY plural (plural) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - - case 'pgsql': - db_query("CREATE TABLE {languages} ( - language varchar(12) NOT NULL default '', - name varchar(64) NOT NULL default '', - native varchar(64) NOT NULL default '', - direction int NOT NULL default '0', - enabled int NOT NULL default '0', - plurals int NOT NULL default '0', - formula varchar(128) NOT NULL default '', - domain varchar(128) NOT NULL default '', - prefix varchar(128) NOT NULL default '', - weight int NOT NULL default '0', - PRIMARY KEY (language) - )"); - db_query("CREATE TABLE {locales_source} ( - lid serial, - location varchar(255) NOT NULL default '', - textgroup varchar(255) NOT NULL default '', - source text NOT NULL, - PRIMARY KEY (lid) - )"); + // Create tables. + drupal_install_schema('locale'); - db_query("CREATE TABLE {locales_target} ( - lid int NOT NULL default '0', - translation text NOT NULL, - language varchar(12) NOT NULL default '', - plid int NOT NULL default '0', - plural int NOT NULL default '0' - )"); - db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)"); - db_query("CREATE INDEX {locales_target}_language_idx ON {locales_target} (language)"); - db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)"); - db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)"); - db_query("CREATE INDEX {locales_source}_source_idx ON {locales_source} (source)"); - break; - } db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight) VALUES ('en', 'English', 'English', '0', '1', '0')"); } @@ -171,7 +99,6 @@ function locale_update_6002() { * Implementation of hook_uninstall(). */ function locale_uninstall() { - db_query('DROP TABLE {languages}'); - db_query('DROP TABLE {locales_source}'); - db_query('DROP TABLE {locales_target}'); + // Remove tables. + drupal_uninstall_schema('locale'); } diff --git a/modules/locale/locale.schema b/modules/locale/locale.schema new file mode 100644 index 000000000..f949c7878 --- /dev/null +++ b/modules/locale/locale.schema @@ -0,0 +1,51 @@ +<?php +// $Id$ + +function locale_schema() { + $schema['languages'] = array( + 'fields' => array( + 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''), + 'name' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'native' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'direction' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'enabled' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'plurals' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'formula' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'domain' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'prefix' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('language'), + ); + + $schema['locales_source'] = array( + 'fields' => array( + 'lid' => array('type' => 'serial', 'not null' => TRUE), + 'location' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'textgroup' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'source' => array('type' => 'text', 'mysql_type' => 'blob', 'not null' => TRUE), + ), + 'primary key' => array('lid'), + 'indexes' => array + ('source' => array(array('source', 30))), + ); + + $schema['locales_target'] = array( + 'fields' => array( + 'lid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'translation' => array('type' => 'text', 'mysql_type' => 'blob', 'not null' => TRUE), + 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''), + 'plid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'plural' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'language' => array('language'), + 'lid' => array('lid'), + 'plid' => array('plid'), + 'plural' => array('plural') + ), + ); + + return $schema; +} + diff --git a/modules/menu/menu.install b/modules/menu/menu.install index e72e1f970..8bb15c92b 100644 --- a/modules/menu/menu.install +++ b/modules/menu/menu.install @@ -5,41 +5,15 @@ * Implementation of hook_install(). */ function menu_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {menu_custom} ( - path varchar(255) NOT NULL default '' , - disabled int NOT NULL default 0, - title varchar(255) NOT NULL default '', - description varchar(255) NOT NULL default '', - weight int NOT NULL default 0 , - type int NOT NULL default 0 , - admin int NOT NULL default 0, - parent varchar(255) NOT NULL default '', - PRIMARY KEY (path) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {menu_custom} ( - path varchar(255) NOT NULL default '' , - disabled int NOT NULL default 0, - title varchar(255) NOT NULL default '', - description varchar(255) NOT NULL default '', - weight int NOT NULL default 0 , - type int NOT NULL default 0 , - admin int NOT NULL default 0, - parent varchar(255) NOT NULL default '', - PRIMARY KEY (path) - )"); - break; - } + // Create tables. + drupal_install_schema('menu'); } /** * Implementation of hook_uninstall(). */ function menu_uninstall() { - db_query('DROP TABLE {menu_custom}'); + // Remove tables. + drupal_uninstall_schema('menu'); menu_rebuild(); } diff --git a/modules/menu/menu.schema b/modules/menu/menu.schema new file mode 100644 index 000000000..665aebf93 --- /dev/null +++ b/modules/menu/menu.schema @@ -0,0 +1,72 @@ +<?php +// $Id$ + +function menu_schema() { + $schema['menu_router'] = array( + 'fields' => array( + 'path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'load_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'to_arg_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'access_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'access_arguments' => array('type' => 'text', 'not null' => FALSE), + 'page_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'page_arguments' => array('type' => 'text', 'not null' => FALSE), + 'fit' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'number_parts' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'tab_parent' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'tab_root' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'title_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'title_arguments' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'type' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'block_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'position' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'file' => array('type' => 'text', 'not null' => FALSE, 'default' => '', 'size' => 'medium') + ), + 'indexes' => array( + 'fit' => array('fit'), + 'tab_parent' => array('tab_parent') + ), + 'primary key' => array('path'), + ); + + $schema['menu_links'] = array( + 'fields' => array( + 'menu_name' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'mlid' => array('type' => 'serial', 'not null' => TRUE), + 'plid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'href' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'router_path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'hidden' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'external' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'has_children' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'expanded' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'depth' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'p1' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'p2' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'p3' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'p4' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'p5' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'p6' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'system'), + 'link_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'options' => array('type' => 'text', 'not null' => FALSE) + ), + 'indexes' => array( + 'expanded_children' => array('expanded', 'has_children'), + 'menu_name_path' => array('menu_name', 'href'), + 'parents' => array('plid', 'p1', 'p2', 'p3', 'p4', 'p5') + ), + 'primary key' => array('mlid'), + ); + + $schema['cache_menu'] = drupal_get_schema_unprocessed('system', 'cache'); + + return $schema; +} + + + diff --git a/modules/node/node.schema b/modules/node/node.schema new file mode 100644 index 000000000..812ef9508 --- /dev/null +++ b/modules/node/node.schema @@ -0,0 +1,107 @@ +<?php +// $Id$ + +function node_schema() { + $schema['node'] = array( + 'fields' => array( + 'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), + 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 1), + 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'changed' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'comment' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'promote' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'moderate' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'sticky' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'nid' => array('nid'), + 'node_changed' => array('changed'), + 'node_created' => array('created'), + 'node_moderate' => array('moderate'), + 'node_promote_status' => array('promote', 'status'), + 'node_status_type' => array('status', 'type', 'nid'), + 'node_title_type' => array('title', array('type', 4)), + 'node_type' => array(array('type', 4)), + 'status' => array('status'), + 'uid' => array('uid') + ), + 'unique keys' => array( + 'nid_vid' => array('nid', 'vid'), + 'vid' => array('vid') + ), + 'primary key' => array('nid'), + ); + + $schema['node_access'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'gid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'realm' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'grant_view' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'grant_update' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'grant_delete' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array( + 'nid', + 'gid', + 'realm' + ), + ); + + $schema['node_counter'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'totalcount' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'big'), + 'daycount' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'medium'), + 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('nid'), + ); + + $schema['node_revisions'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'vid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'body' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'teaser' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'log' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'nid' => array('nid'), + 'uid' => array('uid') + ), + 'primary key' => array('vid'), + ); + + $schema['node_type'] = array( + 'fields' => array( + 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE), + 'description' => array('type' => 'text', 'not null' => TRUE, 'size' => 'medium'), + 'help' => array('type' => 'text', 'not null' => TRUE, 'size' => 'medium'), + 'has_title' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'size' => 'tiny'), + 'title_label' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'has_body' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'size' => 'tiny'), + 'body_label' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'min_word_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'size' => 'small'), + 'custom' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'modified' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'locked' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'orig_type' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '') + ), + 'primary key' => array('type'), + ); + + return $schema; +} + diff --git a/modules/poll/poll.install b/modules/poll/poll.install index 733d71c65..877b6ed48 100644 --- a/modules/poll/poll.install +++ b/modules/poll/poll.install @@ -5,73 +5,14 @@ * Implementation of hook_install(). */ function poll_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {poll} ( - nid int unsigned NOT NULL default '0', - runtime int NOT NULL default '0', - active int unsigned NOT NULL default '0', - PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {poll_votes} ( - nid int unsigned NOT NULL, - uid int unsigned NOT NULL default 0, - chorder int NOT NULL default -1, - hostname varchar(128) NOT NULL default '', - INDEX (nid), - INDEX (uid), - INDEX (hostname) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {poll_choices} ( - chid int unsigned NOT NULL auto_increment, - nid int unsigned NOT NULL default '0', - chtext varchar(128) NOT NULL default '', - chvotes int NOT NULL default '0', - chorder int NOT NULL default '0', - PRIMARY KEY (chid), - KEY nid (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - - case 'pgsql': - db_query("CREATE TABLE {poll} ( - nid int_unsigned NOT NULL default '0', - runtime int NOT NULL default '0', - active int_unsigned NOT NULL default '0', - PRIMARY KEY (nid) - )"); - - db_query("CREATE TABLE {poll_votes} ( - nid int_unsigned NOT NULL, - uid int_unsigned NOT NULL default 0, - chorder int NOT NULL default -1, - hostname varchar(128) NOT NULL default '' - )"); - db_query("CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)"); - db_query("CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)"); - db_query("CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)"); - - db_query("CREATE TABLE {poll_choices} ( - chid serial CHECK (chid >= 0), - nid int_unsigned NOT NULL default '0', - chtext varchar(128) NOT NULL default '', - chvotes int NOT NULL default '0', - chorder int NOT NULL default '0', - PRIMARY KEY (chid) - )"); - db_query("CREATE INDEX {poll_choices}_nid_idx ON {poll_choices} (nid)"); - break; - } + // Create tables. + drupal_install_schema('poll'); } /** * Implementation of hook_uninstall(). */ function poll_uninstall() { - db_query('DROP TABLE {poll}'); - db_query('DROP TABLE {poll_votes}'); - db_query('DROP TABLE {poll_choices}'); + // Remove tables. + drupal_uninstall_schema('poll'); } diff --git a/modules/poll/poll.schema b/modules/poll/poll.schema new file mode 100644 index 000000000..7a9a35509 --- /dev/null +++ b/modules/poll/poll.schema @@ -0,0 +1,42 @@ +<?php +// $Id$ + +function poll_schema() { + $schema['poll'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'runtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'active' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('nid'), + ); + + $schema['poll_choices'] = array( + 'fields' => array( + 'chid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'chtext' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'chvotes' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'chorder' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array('nid' => array('nid')), + 'primary key' => array('chid'), + ); + + $schema['poll_votes'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'chorder' => array('type' => 'int', 'not null' => TRUE, 'default' => -1), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '') + ), + 'indexes' => array( + 'hostname' => array('hostname'), + 'nid' => array('nid'), + 'uid' => array('uid') + ), + ); + + return $schema; +} + diff --git a/modules/profile/profile.install b/modules/profile/profile.install index 8b79ac396..8e645c28f 100644 --- a/modules/profile/profile.install +++ b/modules/profile/profile.install @@ -5,73 +5,16 @@ * Implementation of hook_install(). */ function profile_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {profile_fields} ( - fid int NOT NULL auto_increment, - title varchar(255) default NULL, - name varchar(128) default NULL, - explanation TEXT, - category varchar(255) default NULL, - page varchar(255) default NULL, - type varchar(128) default NULL, - weight tinyint DEFAULT '0' NOT NULL, - required tinyint DEFAULT '0' NOT NULL, - register tinyint DEFAULT '0' NOT NULL, - visibility tinyint DEFAULT '0' NOT NULL, - autocomplete tinyint DEFAULT '0' NOT NULL, - options text, - KEY category (category), - UNIQUE KEY name (name), - PRIMARY KEY (fid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {profile_values} ( - fid int unsigned default '0', - uid int unsigned default '0', - value text, - KEY uid (uid), - KEY fid (fid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - - case 'pgsql': - db_query("CREATE TABLE {profile_fields} ( - fid serial, - title varchar(255) default NULL, - name varchar(128) default NULL, - explanation TEXT default NULL, - category varchar(255) default NULL, - page varchar(255) default NULL, - type varchar(128) default NULL, - weight smallint DEFAULT '0' NOT NULL, - required smallint DEFAULT '0' NOT NULL, - register smallint DEFAULT '0' NOT NULL, - visibility smallint DEFAULT '0' NOT NULL, - autocomplete smallint DEFAULT '0' NOT NULL, - options text, - UNIQUE (name), - PRIMARY KEY (fid) - )"); - db_query("CREATE INDEX {profile_fields}_category_idx ON {profile_fields} (category)"); - - db_query("CREATE TABLE {profile_values} ( - fid int_unsigned default '0', - uid int_unsigned default '0', - value text - )"); - db_query("CREATE INDEX {profile_values}_uid_idx ON {profile_values} (uid)"); - db_query("CREATE INDEX {profile_values}_fid_idx ON {profile_values} (fid)"); - break; - } + // Create tables. + drupal_install_schema('profile'); } /** * Implementation of hook_uninstall(). */ function profile_uninstall() { - db_query('DROP TABLE {profile_fields}'); - db_query('DROP TABLE {profile_values}'); + // Remove tables + drupal_uninstall_schema('profile'); + variable_del('profile_block_author_fields'); } diff --git a/modules/profile/profile.schema b/modules/profile/profile.schema new file mode 100644 index 000000000..64bf35620 --- /dev/null +++ b/modules/profile/profile.schema @@ -0,0 +1,40 @@ +<?php +// $Id$ + +function profile_schema() { + $schema['profile_fields'] = array( + 'fields' => array( + 'fid' => array('type' => 'serial', 'not null' => TRUE), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), + 'name' => array('type' => 'varchar', 'length' => 128, 'not null' => FALSE), + 'explanation' => array('type' => 'text', 'not null' => FALSE), + 'category' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), + 'page' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), + 'type' => array('type' => 'varchar', 'length' => 128, 'not null' => FALSE), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'required' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'register' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'visibility' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'autocomplete' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'options' => array('type' => 'text', 'not null' => FALSE) + ), + 'indexes' => array('category' => array('category')), + 'unique keys' => array('name' => array('name')), + 'primary key' => array('fid'), + ); + + $schema['profile_values'] = array( + 'fields' => array( + 'fid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0), + 'value' => array('type' => 'text', 'not null' => FALSE) + ), + 'indexes' => array( + 'fid' => array('fid'), + 'uid' => array('uid') + ), + ); + + return $schema; +} + diff --git a/modules/search/search.install b/modules/search/search.install index 2b0391a3a..c4ae2571d 100644 --- a/modules/search/search.install +++ b/modules/search/search.install @@ -5,70 +5,17 @@ * Implementation of hook_install(). */ function search_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {search_dataset} ( - sid int unsigned NOT NULL default '0', - type varchar(16) default NULL, - data longtext NOT NULL, - KEY sid_type (sid, type) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {search_index} ( - word varchar(50) NOT NULL default '', - sid int unsigned NOT NULL default '0', - type varchar(16) default NULL, - fromsid int unsigned NOT NULL default '0', - fromtype varchar(16) default NULL, - score float default NULL, - KEY sid_type (sid, type), - KEY from_sid_type (fromsid, fromtype), - KEY word (word) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {search_total} ( - word varchar(50) NOT NULL default '', - count float default NULL, - PRIMARY KEY (word) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {search_dataset} ( - sid int_unsigned NOT NULL default '0', - type varchar(16) default NULL, - data text NOT NULL - )"); - db_query("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset} (sid, type)"); - - db_query("CREATE TABLE {search_index} ( - word varchar(50) NOT NULL default '', - sid int_unsigned NOT NULL default '0', - type varchar(16) default NULL, - fromsid int_unsigned NOT NULL default '0', - fromtype varchar(16) default NULL, - score float default NULL - )"); - db_query("CREATE INDEX {search_index}_sid_type_idx ON {search_index} (sid, type)"); - db_query("CREATE INDEX {search_index}_from_sid_type_idx ON {search_index} (fromsid, fromtype)"); - db_query("CREATE INDEX {search_index}_word_idx ON {search_index} (word)"); - - db_query("CREATE TABLE {search_total} ( - word varchar(50) NOT NULL default '', - count float default NULL, - PRIMARY KEY (word) - )"); - break; - } + // Create tables. + drupal_install_schema('search'); } /** * Implementation of hook_uninstall(). */ function search_uninstall() { - db_query('DROP TABLE {search_dataset}'); - db_query('DROP TABLE {search_index}'); - db_query('DROP TABLE {search_total}'); + // Remove tables. + drupal_uninstall_schema('search'); + variable_del('minimum_word_size'); variable_del('overlap_cjk'); } diff --git a/modules/search/search.schema b/modules/search/search.schema new file mode 100644 index 000000000..a90e3c6a1 --- /dev/null +++ b/modules/search/search.schema @@ -0,0 +1,40 @@ +<?php +// $Id$ + +function search_schema() { + $schema['search_dataset'] = array( + 'fields' => array( + 'sid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'type' => array('type' => 'varchar', 'length' => 16, 'not null' => FALSE), + 'data' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big') + ), + 'indexes' => array('sid_type' => array('sid', 'type')), + ); + + $schema['search_index'] = array( + 'fields' => array( + 'word' => array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''), + 'sid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'type' => array('type' => 'varchar', 'length' => 16, 'not null' => FALSE), + 'fromsid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'fromtype' => array('type' => 'varchar', 'length' => 16, 'not null' => FALSE), + 'score' => array('type' => 'float', 'not null' => FALSE) + ), + 'indexes' => array( + 'from_sid_type' => array('fromsid', 'fromtype'), + 'sid_type' => array('sid', 'type'), + 'word' => array('word') + ), + ); + + $schema['search_total'] = array( + 'fields' => array( + 'word' => array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''), + 'count' => array('type' => 'float', 'not null' => FALSE) + ), + 'primary key' => array('word'), + ); + + return $schema; +} + diff --git a/modules/statistics/statistics.install b/modules/statistics/statistics.install index 2613a640d..61a0be64d 100644 --- a/modules/statistics/statistics.install +++ b/modules/statistics/statistics.install @@ -5,39 +5,8 @@ * Implementation of hook_install(). */ function statistics_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {accesslog} ( - aid int NOT NULL auto_increment, - sid varchar(64) NOT NULL default '', - title varchar(255) default NULL, - path varchar(255) default NULL, - url varchar(255) default NULL, - hostname varchar(128) default NULL, - uid int unsigned default '0', - timer int unsigned NOT NULL default '0', - timestamp int unsigned NOT NULL default '0', - KEY accesslog_timestamp (timestamp), - PRIMARY KEY (aid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {accesslog} ( - aid serial, - sid varchar(64) NOT NULL default '', - title varchar(255) default NULL, - path varchar(255) default NULL, - url varchar(255) default NULL, - hostname varchar(128) default NULL, - uid int_unsigned default '0', - timer int_unsigned NOT NULL default '0', - timestamp int_unsigned NOT NULL default '0', - PRIMARY KEY (aid) - )"); - db_query("CREATE INDEX {accesslog}_accesslog_timestamp_idx ON {accesslog} (timestamp)"); - break; - } + // Create tables. + drupal_install_schema('statistics'); } /** @@ -63,7 +32,9 @@ function statistics_update_1000() { * Implementation of hook_uninstall(). */ function statistics_uninstall() { - db_query('DROP TABLE {accesslog}'); + // Remove tables. + drupal_uninstall_schema('statistics'); + variable_del('statistics_count_content_views'); variable_del('statistics_enable_access_log'); variable_del('statistics_flush_accesslog_timer'); diff --git a/modules/statistics/statistics.schema b/modules/statistics/statistics.schema new file mode 100644 index 000000000..a866c0a5f --- /dev/null +++ b/modules/statistics/statistics.schema @@ -0,0 +1,23 @@ +<?php +// $Id$ + +function statistics_schema() { + $schema['accesslog'] = array( + 'fields' => array( + 'aid' => array('type' => 'serial', 'not null' => TRUE), + 'sid' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), + 'path' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), + 'url' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => FALSE), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0), + 'timer' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array('accesslog_timestamp' => array('timestamp')), + 'primary key' => array('aid'), + ); + + return $schema; +} + diff --git a/modules/system/system.install b/modules/system/system.install index c3244cfea..ad34067f1 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -170,493 +170,24 @@ function system_requirements($phase) { * Implementation of hook_install(). */ function system_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {access} ( - aid int NOT NULL auto_increment, - mask varchar(255) NOT NULL default '', - type varchar(255) NOT NULL default '', - status tinyint NOT NULL default '0', - PRIMARY KEY (aid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {authmap} ( - aid int unsigned NOT NULL auto_increment, - uid int NOT NULL default '0', - authname varchar(128) NOT NULL default '', - module varchar(128) NOT NULL default '', - PRIMARY KEY (aid), - UNIQUE KEY authname (authname) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {batch} ( - bid int(11) NOT NULL, - token varchar(64) NOT NULL, - timestamp int(11) NOT NULL, - batch longtext, - PRIMARY KEY (bid), - KEY token (token) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {blocks} ( - bid int NOT NULL AUTO_INCREMENT, - module varchar(64) DEFAULT '' NOT NULL, - delta varchar(32) NOT NULL default '0', - theme varchar(255) NOT NULL default '', - status tinyint DEFAULT '0' NOT NULL, - weight tinyint DEFAULT '0' NOT NULL, - region varchar(64) DEFAULT 'left' NOT NULL, - custom tinyint DEFAULT '0' NOT NULL, - throttle tinyint DEFAULT '0' NOT NULL, - visibility tinyint DEFAULT '0' NOT NULL, - pages text NOT NULL, - title varchar(64) DEFAULT '' NOT NULL, - PRIMARY KEY (bid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {boxes} ( - bid int NOT NULL, - body longtext, - info varchar(128) NOT NULL default '', - format int NOT NULL default '0', - PRIMARY KEY (bid), - UNIQUE KEY info (info) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {cache} ( - cid varchar(255) NOT NULL default '', - data longblob, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized int(1) NOT NULL default '0', - PRIMARY KEY (cid), - INDEX expire (expire) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - db_query("CREATE TABLE {cache_filter} ( - cid varchar(255) NOT NULL default '', - data longblob, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized int(1) NOT NULL default '0', - PRIMARY KEY (cid), - INDEX expire (expire) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - db_query("CREATE TABLE {cache_page} ( - cid varchar(255) BINARY NOT NULL default '', - data longblob, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized int(1) NOT NULL default '0', - PRIMARY KEY (cid), - INDEX expire (expire) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - db_query("CREATE TABLE {cache_form} ( - cid varchar(255) BINARY NOT NULL default '', - data longblob, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized int(1) NOT NULL default '0', - PRIMARY KEY (cid), - INDEX expire (expire) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {comments} ( - cid int NOT NULL auto_increment, - pid int NOT NULL default '0', - nid int NOT NULL default '0', - uid int NOT NULL default '0', - subject varchar(64) NOT NULL default '', - comment longtext NOT NULL, - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - score mediumint NOT NULL default '0', - status tinyint unsigned NOT NULL default '0', - format int NOT NULL default '0', - thread varchar(255) NOT NULL, - users longtext, - name varchar(60) default NULL, - mail varchar(64) default NULL, - homepage varchar(255) default NULL, - PRIMARY KEY (cid), - KEY lid (nid), - KEY status (status) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {node_comment_statistics} ( - nid int unsigned NOT NULL auto_increment, - last_comment_timestamp int NOT NULL default '0', - last_comment_name varchar(60) default NULL, - last_comment_uid int NOT NULL default '0', - comment_count int unsigned NOT NULL default '0', - PRIMARY KEY (nid), - KEY node_comment_timestamp (last_comment_timestamp) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {files} ( - fid int unsigned NOT NULL default 0, - nid int unsigned NOT NULL default 0, - filename varchar(255) NOT NULL default '', - filepath varchar(255) NOT NULL default '', - filemime varchar(255) NOT NULL default '', - filesize int unsigned NOT NULL default 0, - PRIMARY KEY (fid), - KEY nid (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {file_revisions} ( - fid int unsigned NOT NULL default 0, - vid int unsigned NOT NULL default 0, - description varchar(255) NOT NULL default '', - list tinyint unsigned NOT NULL default 0, - PRIMARY KEY (fid, vid), - KEY (vid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {filter_formats} ( - format int NOT NULL auto_increment, - name varchar(255) NOT NULL default '', - roles varchar(255) NOT NULL default '', - cache tinyint NOT NULL default '0', - PRIMARY KEY (format), - UNIQUE KEY (name) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {filters} ( - fid int NOT NULL AUTO_INCREMENT, - format int NOT NULL default '0', - module varchar(64) NOT NULL default '', - delta tinyint DEFAULT '0' NOT NULL, - weight tinyint DEFAULT '0' NOT NULL, - PRIMARY KEY (fid), - INDEX (weight) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {flood} ( - fid int NOT NULL AUTO_INCREMENT, - event varchar(64) NOT NULL default '', - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - PRIMARY KEY (fid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {history} ( - uid int NOT NULL default '0', - nid int NOT NULL default '0', - timestamp int NOT NULL default '0', - PRIMARY KEY (uid,nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {menu_router} ( - path varchar(255) NOT NULL default '', - load_functions varchar(255) NOT NULL default '', - to_arg_functions varchar(255) NOT NULL default '', - access_callback varchar(255) NOT NULL default '', - access_arguments text, - page_callback varchar(255) NOT NULL default '', - page_arguments text, - fit int NOT NULL default 0, - number_parts int NOT NULL default 0, - tab_parent varchar(255) NOT NULL default '', - tab_root varchar(255) NOT NULL default '', - title varchar(255) NOT NULL default '', - title_callback varchar(255) NOT NULL default '', - title_arguments varchar(255) NOT NULL default '', - type int NOT NULL default 0, - block_callback varchar(255) NOT NULL default '', - description TEXT, - position varchar(255) NOT NULL default '', - weight int NOT NULL default 0, - file mediumtext, - PRIMARY KEY (path), - KEY fit (fit), - KEY tab_parent (tab_parent) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {menu_links} ( - menu_name varchar(64) NOT NULL default '', - mlid int NOT NULL default '0', - plid int NOT NULL default '0', - href varchar(255) NOT NULL default '', - router_path varchar(255) NOT NULL default '', - hidden smallint NOT NULL default '0', - external smallint NOT NULL default '0', - has_children int NOT NULL default '0', - expanded smallint NOT NULL default '0', - weight int NOT NULL default '0', - depth int NOT NULL default '0', - p1 int NOT NULL default '0', - p2 int NOT NULL default '0', - p3 int NOT NULL default '0', - p4 int NOT NULL default '0', - p5 int NOT NULL default '0', - p6 int NOT NULL default '0', - module varchar(255) NOT NULL default 'system', - link_title varchar(255) NOT NULL default '', - options text, - PRIMARY KEY (mlid), - KEY parents (plid, p1, p2, p3, p4, p5), - KEY menu_name_path (menu_name, href), - KEY menu_expanded_children (expanded, has_children) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {node} ( - nid int unsigned NOT NULL auto_increment, - vid int unsigned NOT NULL default '0', - type varchar(32) NOT NULL default '', - language varchar(12) NOT NULL default '', - title varchar(128) NOT NULL default '', - uid int NOT NULL default '0', - status int NOT NULL default '1', - created int NOT NULL default '0', - changed int NOT NULL default '0', - comment int NOT NULL default '0', - promote int NOT NULL default '0', - moderate int NOT NULL default '0', - sticky int NOT NULL default '0', - PRIMARY KEY (nid), - UNIQUE KEY nid_vid (nid, vid), - UNIQUE KEY vid (vid), - KEY node_type (type(4)), - KEY node_title_type (title, type(4)), - KEY status (status), - KEY uid (uid), - KEY node_moderate (moderate), - KEY node_promote_status (promote, status), - KEY node_created (created), - KEY node_changed (changed), - KEY node_status_type (status, type, nid), - KEY nid (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {node_access} ( - nid int unsigned NOT NULL default '0', - gid int unsigned NOT NULL default '0', - realm varchar(255) NOT NULL default '', - grant_view tinyint unsigned NOT NULL default '0', - grant_update tinyint unsigned NOT NULL default '0', - grant_delete tinyint unsigned NOT NULL default '0', - PRIMARY KEY (nid,gid,realm) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {node_revisions} ( - nid int unsigned NOT NULL, - vid int unsigned NOT NULL, - uid int NOT NULL default '0', - title varchar(128) NOT NULL default '', - body longtext NOT NULL, - teaser longtext NOT NULL, - log longtext NOT NULL, - timestamp int NOT NULL default '0', - format int NOT NULL default '0', - PRIMARY KEY (vid), - KEY nid (nid), - KEY uid (uid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {node_type} ( - type varchar(32) NOT NULL, - name varchar(255) NOT NULL default '', - module varchar(255) NOT NULL, - description mediumtext NOT NULL, - help mediumtext NOT NULL, - has_title tinyint unsigned NOT NULL, - title_label varchar(255) NOT NULL default '', - has_body tinyint unsigned NOT NULL, - body_label varchar(255) NOT NULL default '', - min_word_count smallint unsigned NOT NULL, - custom tinyint NOT NULL DEFAULT '0', - modified tinyint NOT NULL DEFAULT '0', - locked tinyint NOT NULL DEFAULT '0', - orig_type varchar(255) NOT NULL default '', - PRIMARY KEY (type) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {url_alias} ( - pid int unsigned NOT NULL auto_increment, - src varchar(128) NOT NULL default '', - dst varchar(128) NOT NULL default '', - language varchar(12) NOT NULL default '', - PRIMARY KEY (pid), - UNIQUE KEY dst_language (dst, language), - KEY src (src) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {permission} ( - pid int NOT NULL AUTO_INCREMENT, - rid int unsigned NOT NULL default '0', - perm longtext, - tid int unsigned NOT NULL default '0', - PRIMARY KEY (pid), - KEY rid (rid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {role} ( - rid int unsigned NOT NULL auto_increment, - name varchar(64) NOT NULL default '', - PRIMARY KEY (rid), - UNIQUE KEY name (name) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {blocks_roles} ( - module varchar(64) NOT NULL, - delta varchar(32) NOT NULL, - rid int unsigned NOT NULL, - PRIMARY KEY (module, delta, rid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {sessions} ( - uid int unsigned NOT NULL, - sid varchar(64) NOT NULL default '', - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - cache int NOT NULL default '0', - session longtext, - KEY uid (uid), - PRIMARY KEY (sid), - KEY timestamp (timestamp) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {sequences} ( - name varchar(255) NOT NULL default '', - id int unsigned NOT NULL default '0', - PRIMARY KEY (name) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {node_counter} ( - nid int NOT NULL default '0', - totalcount bigint unsigned NOT NULL default '0', - daycount mediumint unsigned NOT NULL default '0', - timestamp int unsigned NOT NULL default '0', - PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {system} ( - filename varchar(255) NOT NULL default '', - name varchar(255) NOT NULL default '', - type varchar(255) NOT NULL default '', - owner varchar(255) NOT NULL default '', - status int NOT NULL default '0', - throttle tinyint DEFAULT '0' NOT NULL, - bootstrap int NOT NULL default '0', - schema_version smallint NOT NULL default -1, - weight int NOT NULL default '0', - info text, - PRIMARY KEY (filename), - KEY (weight) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {term_data} ( - tid int unsigned NOT NULL auto_increment, - vid int unsigned NOT NULL default '0', - name varchar(255) NOT NULL default '', - description longtext, - weight tinyint NOT NULL default '0', - PRIMARY KEY (tid), - KEY vid (vid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {term_hierarchy} ( - tid int unsigned NOT NULL default '0', - parent int unsigned NOT NULL default '0', - KEY tid (tid), - KEY parent (parent), - PRIMARY KEY (tid, parent) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {term_node} ( - nid int unsigned NOT NULL default '0', - vid int unsigned NOT NULL default '0', - tid int unsigned NOT NULL default '0', - KEY nid (nid), - KEY vid (vid), - KEY tid (tid), - PRIMARY KEY (vid,tid,nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {term_relation} ( - trid int NOT NULL AUTO_INCREMENT, - tid1 int unsigned NOT NULL default '0', - tid2 int unsigned NOT NULL default '0', - PRIMARY KEY (trid), - KEY tid1 (tid1), - KEY tid2 (tid2) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {term_synonym} ( - tsid int NOT NULL AUTO_INCREMENT, - tid int unsigned NOT NULL default '0', - name varchar(255) NOT NULL default '', - PRIMARY KEY (tsid), - KEY tid (tid), - KEY name (name(3)) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {users} ( - uid int unsigned NOT NULL default '0', - name varchar(60) NOT NULL default '', - pass varchar(32) NOT NULL default '', - mail varchar(64) default '', - mode tinyint NOT NULL default '0', - sort tinyint default '0', - threshold tinyint default '0', - theme varchar(255) NOT NULL default '', - signature varchar(255) NOT NULL default '', - created int NOT NULL default '0', - access int NOT NULL default '0', - login int NOT NULL default '0', - status tinyint NOT NULL default '0', - timezone varchar(8) default NULL, - language varchar(12) NOT NULL default '', - picture varchar(255) NOT NULL DEFAULT '', - init varchar(64) default '', - data longtext, - PRIMARY KEY (uid), - UNIQUE KEY name (name), - KEY created (created), - KEY access (access) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {users_roles} ( - uid int unsigned NOT NULL default '0', - rid int unsigned NOT NULL default '0', - PRIMARY KEY (uid, rid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {variable} ( - name varchar(128) NOT NULL default '', - value longtext NOT NULL, - language varchar(12) NOT NULL default '', - PRIMARY KEY (name, language) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {vocabulary} ( - vid int unsigned NOT NULL auto_increment, - name varchar(255) NOT NULL default '', - description longtext, - help varchar(255) NOT NULL default '', - relations tinyint unsigned NOT NULL default '0', - hierarchy tinyint unsigned NOT NULL default '0', - multiple tinyint unsigned NOT NULL default '0', - required tinyint unsigned NOT NULL default '0', - tags tinyint unsigned NOT NULL default '0', - module varchar(255) NOT NULL default '', - weight tinyint NOT NULL default '0', - PRIMARY KEY (vid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {vocabulary_node_types} ( - vid int unsigned NOT NULL DEFAULT '0', - type varchar(32) NOT NULL DEFAULT '', - PRIMARY KEY (vid, type) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - break; - case 'pgsql': + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + // As of Drupal 6, users.uid is an auto-incrementing column, but + // previously it was not. Below, we insert a row with uid 0 to + // represent user anonymous. By default, mysql treats that as + // requesting the next sequence value which, of course, is uid + // 1! This statement turns off that behavior for the duration + // of the current request, which is all we need. + // + // Note that this statement must be run any time the uid column + // is inserted or altered. That includes loading mysqldump + // backups, but mysqldump puts this statement in all backups for + // this exact reason. It also includes any Schema API + // table-altering operations on the users table. + db_query("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'"); + break; + case 'pgsql': /* create unsigned types */ db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)"); db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)"); @@ -692,492 +223,13 @@ function system_install() { \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\' LANGUAGE \'sql\'' ); + break; + } - /* create tables */ - db_query("CREATE TABLE {access} ( - aid serial, - mask varchar(255) NOT NULL default '', - type varchar(255) NOT NULL default '', - status smallint NOT NULL default '0', - PRIMARY KEY (aid) - )"); - - db_query("CREATE TABLE {authmap} ( - aid serial CHECK (aid >= 0), - uid int NOT NULL default '0', - authname varchar(128) NOT NULL default '', - module varchar(128) NOT NULL default '', - PRIMARY KEY (aid), - UNIQUE (authname) - )"); - - db_query("CREATE TABLE {batch} ( - bid serial CHECK (bid >= 0), - token varchar(64) NOT NULL default '', - timestamp int NOT NULL default '0', - batch text, - PRIMARY KEY (bid) - )"); - db_query("CREATE INDEX {batch}_token_idx ON {batch} (token)"); - - db_query("CREATE TABLE {blocks} ( - bid serial, - module varchar(64) DEFAULT '' NOT NULL, - delta varchar(32) NOT NULL default '0', - theme varchar(255) NOT NULL default '', - status smallint DEFAULT '0' NOT NULL, - weight smallint DEFAULT '0' NOT NULL, - region varchar(64) DEFAULT 'left' NOT NULL, - custom smallint DEFAULT '0' NOT NULL, - throttle smallint DEFAULT '0' NOT NULL, - visibility smallint DEFAULT '0' NOT NULL, - pages text DEFAULT '' NOT NULL, - title varchar(64) DEFAULT '' NOT NULL, - PRIMARY KEY (bid) - )"); - - db_query("CREATE TABLE {boxes} ( - bid serial, - body text, - info varchar(128) NOT NULL default '', - format smallint NOT NULL default '0', - PRIMARY KEY (bid), - UNIQUE (info) - )"); - - db_query("CREATE TABLE {cache} ( - cid varchar(255) NOT NULL default '', - data bytea, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized smallint NOT NULL default '0', - PRIMARY KEY (cid) - )"); - db_query("CREATE TABLE {cache_filter} ( - cid varchar(255) NOT NULL default '', - data bytea, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized smallint NOT NULL default '0', - PRIMARY KEY (cid) - )"); - db_query("CREATE TABLE {cache_page} ( - cid varchar(255) NOT NULL default '', - data bytea, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized smallint NOT NULL default '0', - PRIMARY KEY (cid) - )"); - db_query("CREATE TABLE {cache_form} ( - cid varchar(255) NOT NULL default '', - data bytea, - expire int NOT NULL default '0', - created int NOT NULL default '0', - headers text, - serialized smallint NOT NULL default '0', - PRIMARY KEY (cid) - )"); - db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)"); - db_query("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)"); - db_query("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)"); - db_query("CREATE INDEX {cache_form}_expire_idx ON {cache_form} (expire)"); - - db_query("CREATE TABLE {comments} ( - cid serial, - pid int NOT NULL default '0', - nid int NOT NULL default '0', - uid int NOT NULL default '0', - subject varchar(64) NOT NULL default '', - comment text NOT NULL, - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - score int NOT NULL default '0', - status smallint_unsigned NOT NULL default '0', - format smallint NOT NULL default '0', - thread varchar(255) NOT NULL, - users text, - name varchar(60) default NULL, - mail varchar(64) default NULL, - homepage varchar(255) default NULL, - PRIMARY KEY (cid) - )"); - db_query("CREATE INDEX {comments}_nid_idx ON {comments} (nid)"); - db_query("CREATE INDEX {comments}_status_idx ON {comments} (status)"); - - db_query("CREATE TABLE {node_comment_statistics} ( - nid serial CHECK (nid >= 0), - last_comment_timestamp int NOT NULL default '0', - last_comment_name varchar(60) default NULL, - last_comment_uid int NOT NULL default '0', - comment_count int_unsigned NOT NULL default '0', - PRIMARY KEY (nid) - )"); - db_query("CREATE INDEX {node_comment_statistics}_node_comment_timestamp_idx ON {node_comment_statistics} (last_comment_timestamp)"); - - db_query("CREATE TABLE {files} ( - fid serial CHECK (fid >= 0), - nid int_unsigned NOT NULL default 0, - filename varchar(255) NOT NULL default '', - filepath varchar(255) NOT NULL default '', - filemime varchar(255) NOT NULL default '', - filesize int_unsigned NOT NULL default 0, - PRIMARY KEY (fid) - )"); - db_query("CREATE INDEX {files}_nid_idx ON {files} (nid)"); - - db_query("CREATE TABLE {file_revisions} ( - fid int_unsigned NOT NULL default 0, - vid int_unsigned NOT NULL default 0, - description varchar(255) NOT NULL default '', - list smallint_unsigned NOT NULL default 0, - PRIMARY KEY (fid, vid) - )"); - db_query("CREATE INDEX {file_revisions}_vid_idx ON {file_revisions} (vid)"); - - db_query("CREATE TABLE {filter_formats} ( - format serial, - name varchar(255) NOT NULL default '', - roles varchar(255) NOT NULL default '', - cache smallint NOT NULL default '0', - PRIMARY KEY (format), - UNIQUE (name) - )"); - - db_query("CREATE TABLE {filters} ( - fid serial, - format int NOT NULL default '0', - module varchar(64) NOT NULL default '', - delta smallint DEFAULT '0' NOT NULL, - weight smallint DEFAULT '0' NOT NULL, - PRIMARY KEY (fid) - )"); - db_query("CREATE INDEX {filters}_weight_idx ON {filters} (weight)"); - - db_query("CREATE TABLE {flood} ( - fid serial, - event varchar(64) NOT NULL default '', - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - PRIMARY KEY (fid) - )"); - - db_query("CREATE TABLE {history} ( - uid int NOT NULL default '0', - nid int NOT NULL default '0', - timestamp int NOT NULL default '0', - PRIMARY KEY (uid,nid) - )"); - - db_query("CREATE TABLE {menu_router} ( - path varchar(255) NOT NULL default '', - load_functions varchar(255) NOT NULL default '', - to_arg_functions varchar(255) NOT NULL default '', - access_callback varchar(255) NOT NULL default '', - access_arguments text, - page_callback varchar(255) NOT NULL default '', - page_arguments text, - fit int NOT NULL default 0, - number_parts int NOT NULL default 0, - tab_parent varchar(255) NOT NULL default '', - tab_root varchar(255) NOT NULL default '', - title varchar(255) NOT NULL default '', - title_callback varchar(255) NOT NULL default '', - title_arguments varchar(255) NOT NULL default '', - type int NOT NULL default 0, - block_callback varchar(255) NOT NULL default '', - description TEXT, - position varchar(255) NOT NULL default '', - weight int NOT NULL default 0, - file text, - PRIMARY KEY (path) - )"); - db_query("CREATE INDEX {menu_router}_fit_idx ON {menu_router} (fit)"); - db_query("CREATE INDEX {menu_router}_tab_parent_idx ON {menu_router} (tab_parent)"); - - db_query("CREATE TABLE {menu_links} ( - menu_name varchar(64) NOT NULL default '', - mlid serial, - plid int NOT NULL default '0', - href varchar(255) NOT NULL default '', - router_path varchar(255) NOT NULL default '', - hidden smallint NOT NULL default '0', - external smallint NOT NULL default '0', - has_children int NOT NULL default '0', - expanded smallint NOT NULL default '0', - weight int NOT NULL default '0', - depth int NOT NULL default '0', - p1 int NOT NULL default '0', - p2 int NOT NULL default '0', - p3 int NOT NULL default '0', - p4 int NOT NULL default '0', - p5 int NOT NULL default '0', - p6 int NOT NULL default '0', - module varchar(255) NOT NULL default 'system', - link_title varchar(255) NOT NULL default '', - options text, - PRIMARY KEY (mlid) - )"); - db_query("CREATE INDEX {menu_links}_parents_idx ON {menu_links} (plid, p1, p2, p3, p4, p5)"); - db_query("CREATE INDEX {menu_links}_menu_name_idx ON {menu_links} (menu_name, href)"); - db_query("CREATE INDEX {menu_links}_expanded_children_idx ON {menu_links} (expanded, has_children)"); - - db_query("CREATE TABLE {node} ( - nid serial CHECK (nid >= 0), - vid int_unsigned NOT NULL default '0', - type varchar(32) NOT NULL default '', - language varchar(12) NOT NULL default '', - title varchar(128) NOT NULL default '', - uid int NOT NULL default '0', - status int NOT NULL default '1', - created int NOT NULL default '0', - changed int NOT NULL default '0', - comment int NOT NULL default '0', - promote int NOT NULL default '0', - moderate int NOT NULL default '0', - sticky int NOT NULL default '0', - PRIMARY KEY (nid), - UNIQUE (nid, vid), - UNIQUE (vid) - )"); - db_query("CREATE INDEX {node}_node_type_idx ON {node} (substr (type, 1, 4))"); - db_query("CREATE INDEX {node}_node_title_type_idx ON {node} (title, substr(type, 1, 4))"); - db_query("CREATE INDEX {node}_status_idx ON {node} (status)"); - db_query("CREATE INDEX {node}_uid_idx ON {node} (uid)"); - db_query("CREATE INDEX {node}_node_moderate_idx ON {node} (moderate)"); - db_query("CREATE INDEX {node}_node_promote_status_idx ON {node} (promote, status)"); - db_query("CREATE INDEX {node}_node_created_idx ON {node} (created)"); - db_query("CREATE INDEX {node}_node_changed_idx ON {node} (changed)"); - db_query("CREATE INDEX {node}_node_status_type_idx ON {node} (status, type, nid)"); - db_query("CREATE INDEX {node}_nid_idx ON {node} (nid)"); - - db_query("CREATE TABLE {node_access} ( - nid int_unsigned NOT NULL default '0', - gid int_unsigned NOT NULL default '0', - realm varchar(255) NOT NULL default '', - grant_view smallint_unsigned NOT NULL default '0', - grant_update smallint_unsigned NOT NULL default '0', - grant_delete smallint_unsigned NOT NULL default '0', - PRIMARY KEY (nid,gid,realm) - )"); - - db_query("CREATE TABLE {node_revisions} ( - nid int_unsigned NOT NULL, - vid serial CHECK (vid >= 0), - uid int NOT NULL default '0', - title varchar(128) NOT NULL default '', - body text NOT NULL default '', - teaser text NOT NULL default '', - log text NOT NULL default '', - timestamp int NOT NULL default '0', - format int NOT NULL default '0', - PRIMARY KEY (vid) - )"); - db_query("CREATE INDEX {node_revisions}_nid_idx ON {node_revisions} (nid)"); - db_query("CREATE INDEX {node_revisions}_uid_idx ON {node_revisions} (uid)"); - - db_query("CREATE TABLE {node_type} ( - type varchar(32) NOT NULL, - name varchar(255) NOT NULL default '', - module varchar(255) NOT NULL, - description text NOT NULL, - help text NOT NULL, - has_title smallint_unsigned NOT NULL, - title_label varchar(255) NOT NULL default '', - has_body smallint_unsigned NOT NULL, - body_label varchar(255) NOT NULL default '', - min_word_count smallint_unsigned NOT NULL, - custom smallint NOT NULL DEFAULT '0', - modified smallint NOT NULL DEFAULT '0', - locked smallint NOT NULL DEFAULT '0', - orig_type varchar(255) NOT NULL default '', - PRIMARY KEY (type) - )"); - - db_query("CREATE TABLE {url_alias} ( - pid serial CHECK (pid >= 0), - src varchar(128) NOT NULL default '', - dst varchar(128) NOT NULL default '', - language varchar(12) NOT NULL default '', - PRIMARY KEY (pid) - )"); - db_query("CREATE INDEX {url_alias}_src_idx ON {url_alias} (src)"); - db_query("CREATE UNIQUE INDEX {url_alias}_dst_language_idx ON {url_alias} (dst, language)"); - - db_query("CREATE TABLE {permission} ( - pid serial, - rid int_unsigned NOT NULL default '0', - perm text, - tid int_unsigned NOT NULL default '0', - PRIMARY KEY (pid) - )"); - db_query("CREATE INDEX {permission}_rid_idx ON {permission} (rid)"); - - db_query("CREATE TABLE {role} ( - rid serial CHECK (rid >= 0), - name varchar(64) NOT NULL default '', - PRIMARY KEY (rid), - UNIQUE (name) - )"); - - db_query("CREATE TABLE {blocks_roles} ( - module varchar(64) NOT NULL, - delta varchar(32) NOT NULL, - rid int_unsigned NOT NULL, - PRIMARY KEY (module, delta, rid) - )"); - - db_query("CREATE TABLE {sessions} ( - uid int_unsigned NOT NULL, - sid varchar(64) NOT NULL default '', - hostname varchar(128) NOT NULL default '', - timestamp int NOT NULL default '0', - cache int NOT NULL default '0', - session text, - PRIMARY KEY (sid) - )"); - db_query("CREATE INDEX {sessions}_uid_idx ON {sessions} (uid)"); - db_query("CREATE INDEX {sessions}_timestamp_idx ON {sessions} (timestamp)"); - -/* Only used for MySQL - db_query("CREATE TABLE {sequences} ( - name varchar(255) NOT NULL default '', - id int_unsigned NOT NULL default '0', - PRIMARY KEY (name) - )"); */ - - db_query("CREATE TABLE {node_counter} ( - nid int NOT NULL default '0', - totalcount bigint_unsigned NOT NULL default '0', - daycount int_unsigned NOT NULL default '0', - timestamp int_unsigned NOT NULL default '0', - PRIMARY KEY (nid) - )"); - - db_query("CREATE TABLE {system} ( - filename varchar(255) NOT NULL default '', - name varchar(255) NOT NULL default '', - type varchar(255) NOT NULL default '', - owner varchar(255) NOT NULL default '', - status int NOT NULL default '0', - throttle smallint DEFAULT '0' NOT NULL, - bootstrap int NOT NULL default '0', - schema_version smallint NOT NULL default -1, - weight int NOT NULL default '0', - info text, - PRIMARY KEY (filename) - )"); - db_query("CREATE INDEX {system}_weight_idx ON {system} (weight)"); - - db_query("CREATE TABLE {term_data} ( - tid serial CHECK (tid >= 0), - vid int_unsigned NOT NULL default '0', - name varchar(255) NOT NULL default '', - description text, - weight smallint NOT NULL default '0', - PRIMARY KEY (tid) - )"); - db_query("CREATE INDEX {term_data}_vid_idx ON {term_data} (vid)"); - - db_query("CREATE TABLE {term_hierarchy} ( - tid int_unsigned NOT NULL default '0', - parent int_unsigned NOT NULL default '0', - PRIMARY KEY (tid, parent) - )"); - db_query("CREATE INDEX {term_hierarchy}_tid_idx ON {term_hierarchy} (tid)"); - db_query("CREATE INDEX {term_hierarchy}_parent_idx ON {term_hierarchy} (parent)"); - - db_query("CREATE TABLE {term_node} ( - nid int_unsigned NOT NULL default '0', - vid int_unsigned NOT NULL default '0', - tid int_unsigned NOT NULL default '0', - PRIMARY KEY (tid,nid,vid) - )"); - db_query("CREATE INDEX {term_node}_nid_idx ON {term_node} (nid)"); - db_query("CREATE INDEX {term_node}_vid_idx ON {term_node} (vid)"); - db_query("CREATE INDEX {term_node}_tid_idx ON {term_node} (tid)"); - - db_query("CREATE TABLE {term_relation} ( - trid serial, - tid1 int_unsigned NOT NULL default '0', - tid2 int_unsigned NOT NULL default '0', - PRIMARY KEY (trid) - )"); - db_query("CREATE INDEX {term_relation}_tid1_idx ON {term_relation} (tid1)"); - db_query("CREATE INDEX {term_relation}_tid2_idx ON {term_relation} (tid2)"); - - db_query("CREATE TABLE {term_synonym} ( - tsid serial, - tid int_unsigned NOT NULL default '0', - name varchar(255) NOT NULL default '', - PRIMARY KEY (tsid) - )"); - db_query("CREATE INDEX {term_synonym}_tid_idx ON {term_synonym} (tid)"); - db_query("CREATE INDEX {term_synonym}_name_idx ON {term_synonym} (substr(name, 1, 3))"); - - db_query("CREATE TABLE {users} ( - uid serial CHECK (uid >= 0), - name varchar(60) NOT NULL default '', - pass varchar(32) NOT NULL default '', - mail varchar(64) default '', - mode smallint NOT NULL default '0', - sort smallint default '0', - threshold smallint default '0', - theme varchar(255) NOT NULL default '', - signature varchar(255) NOT NULL default '', - created int NOT NULL default '0', - access int NOT NULL default '0', - login int NOT NULL default '0', - status smallint NOT NULL default '0', - timezone varchar(8) default NULL, - language varchar(12) NOT NULL default '', - picture varchar(255) NOT NULL DEFAULT '', - init varchar(64) default '', - data text, - PRIMARY KEY (uid), - UNIQUE (name) - )"); - db_query("CREATE INDEX {users}_access_idx ON {users} (access)"); - db_query("CREATE INDEX {users}_created_idx ON {users} (created)"); - - db_query("CREATE TABLE {users_roles} ( - uid int_unsigned NOT NULL default '0', - rid int_unsigned NOT NULL default '0', - PRIMARY KEY (uid, rid) - )"); - - db_query("CREATE TABLE {variable} ( - name varchar(128) NOT NULL default '', - value text NOT NULL, - language varchar(12) NOT NULL default '', - PRIMARY KEY (name, language) - )"); - - db_query("CREATE TABLE {vocabulary} ( - vid serial CHECK (vid >= 0), - name varchar(255) NOT NULL default '', - description text, - help varchar(255) NOT NULL default '', - relations smallint_unsigned NOT NULL default '0', - hierarchy smallint_unsigned NOT NULL default '0', - multiple smallint_unsigned NOT NULL default '0', - required smallint_unsigned NOT NULL default '0', - tags smallint_unsigned NOT NULL default '0', - module varchar(255) NOT NULL default '', - weight smallint NOT NULL default '0', - PRIMARY KEY (vid) - )"); - - db_query("CREATE TABLE {vocabulary_node_types} ( - vid int_unsigned NOT NULL DEFAULT '0', - type varchar(32) NOT NULL DEFAULT '', - PRIMARY KEY (vid, type) - )"); - - break; + // Create tables. + $modules = array('system', 'filter', 'block', 'user', 'node', 'menu', 'comment', 'taxonomy'); + foreach ($modules as $module) { + drupal_install_schema($module); } // Load system theme data appropriately. @@ -4093,6 +3145,147 @@ function system_update_6018() { } /** + * Reconcile small differences in the previous, manually created mysql + * and pgsql schemas so they are the same and can be represented by a + * single schema structure. + * + * Note that the mysql and pgsql cases make different changes. This + * is because each schema needs to be tweaked in different ways to + * comform to the new schema structure. Also, since they operate on + * tables defined by many optional core modules which may not ever + * have been installed, they must test each table for existence. If + * the modules are first installed after this update exists the tables + * will be created from the schema structure and will start out + * correct. + */ +function system_update_6019() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'pgsql': + // Remove default ''. + if (db_table_exists('aggregator_feed')) { + db_field_set_no_default($ret, 'aggregator_feed', 'description'); + db_field_set_no_default($ret, 'aggregator_feed', 'image'); + } + db_field_set_no_default($ret, 'blocks', 'pages'); + if (db_table_exists('contact')) { + db_field_set_no_default($ret, 'contact', 'recipients'); + db_field_set_no_default($ret, 'contact', 'reply'); + } + db_field_set_no_default($ret, 'watchdog', 'location'); + db_field_set_no_default($ret, 'node_revisions', 'body'); + db_field_set_no_default($ret, 'node_revisions', 'teaser'); + db_field_set_no_default($ret, 'node_revisions', 'log'); + + // Update from pgsql 'float' (which means 'double precision') to + // schema 'float' (which in pgsql means 'real'). + if (db_table_exists('search_index')) { + db_update_field($ret, 'search_index', 'score'); + } + if (db_table_exists('search_total')) { + db_update_field($ret, 'search_total', 'count'); + } + + // Fix index menu.pid: pgsql code incorrectly had it on parent, not pid. + if (db_table_exists('menu')) { + db_drop_index($ret, 'menu', 'pid'); + db_add_index($ret, 'menu', 'pid', array('pid')); + } + + // Replace unique index dst_language with a unique constraint. The + // result is the same but the unique key fits our current schema + // structure. Also, the postgres documentation implies that + // unique constraints are preferable to unique indexes. See + // http://www.postgresql.org/docs/8.2/interactive/indexes-unique.html. + if (db_table_exists('url_alias')) { + db_drop_index($ret, 'url_alias', 'dst_language'); + db_add_unique_key($ret, 'url_alias', 'dst_language', + array('dst', 'language')); + } + + // Fix term_node pkey: mysql and pgsql code had different orders. + if (db_table_exists('term_node')) { + db_drop_primary_key($ret, 'term_node'); + db_add_primary_key($ret, 'term_node', array('vid', 'tid', 'nid')); + } + + // Remove defaults on batch columns. + if (db_table_exists('batch')) { + db_field_set_no_default($ret, 'batch', 'token'); + db_field_set_no_default($ret, 'batch', 'timestamp'); + } + + // Fix index locales_source.source. + if (db_table_exists('locales_source')) { + db_drop_index($ret, 'locales_source', 'source'); + db_add_index($ret, 'locales_source', 'source', + array(array('source', 30))); + } + + // Rename unique key node.nid to node.nid_vid. + db_drop_unique_key($ret, 'node', 'nid'); + db_add_unique_key($ret, 'node', 'nid_vid', array('nid', 'vid')); + + break; + + case 'mysql': + case 'mysqli': + // Rename key 'link' to 'url'. + if (db_table_exists('aggregator_feed')) { + db_drop_unique_key($ret, 'aggregator_feed', 'link'); + db_add_unique_key($ret, 'aggregator_feed', 'url', array('url')); + } + + // Change to size => small. + if (db_table_exists('boxes')) { + db_update_field($ret, 'boxes', 'format'); + } + + // Change to size => small. + // Rename index 'lid' to 'nid'. + if (db_table_exists('comments')) { + db_update_field($ret, 'comments', 'format'); + db_drop_index($ret, 'comments', 'lid'); + db_add_index($ret, 'comments', 'nid', array('nid')); + } + + // Rename index 'lang' to 'language'. + if (db_table_exists('locales_target')) { + db_drop_index($ret, 'locales_target', 'lang'); + db_add_index($ret, 'locales_target', 'language', array('language')); + } + + // Change to size => small. + db_update_field($ret, 'cache', 'serialized'); + db_update_field($ret, 'cache_filter', 'serialized'); + db_update_field($ret, 'cache_page', 'serialized'); + db_update_field($ret, 'cache_form', 'serialized'); + + // Remove default => 0, set auto increment. + db_update_field($ret, 'files', 'fid'); + + // Remove default => 0, set auto increment. + $ret[] = update_sql("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'"); + db_update_field($ret, 'users', 'uid'); + + // Set auto increment. + db_update_field($ret, 'node_revisions', 'vid'); + + // Set auto increment. + db_update_field($ret, 'boxes', 'bid'); + + // Set auto increment, unsigned. + db_update_field($ret, 'batch', 'bid'); + + break; + } + + return $ret; +} + + +/** * @} End of "defgroup updates-5.x-to-6.x" * The next series of updates should start at 7000. */ diff --git a/modules/system/system.schema b/modules/system/system.schema new file mode 100644 index 000000000..2df482d2e --- /dev/null +++ b/modules/system/system.schema @@ -0,0 +1,139 @@ +<?php +// $Id$ + +function system_schema() { + $schema['batch'] = array( + 'fields' => array( + 'bid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'token' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), + 'timestamp' => array('type' => 'int', 'not null' => TRUE), + 'batch' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big') + ), + 'primary key' => array('bid'), + 'indexes' => array('token' => array('token')), + ); + + $schema['cache'] = array( + 'fields' => array( + 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'), + 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'headers' => array('type' => 'text', 'not null' => FALSE), + 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array('expire' => array('expire')), + 'primary key' => array('cid'), + ); + + $schema['cache_form'] = $schema['cache']; + $schema['cache_page'] = $schema['cache']; + + $schema['files'] = array( + 'fields' => array( + 'fid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'filepath' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'filemime' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'filesize' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array('nid' => array('nid')), + 'primary key' => array('fid'), + ); + + $schema['file_revisions'] = array( + 'fields' => array( + 'fid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'list' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array('fid', 'vid'), + 'indexes' => array('vid' => array('vid')), + ); + + $schema['flood'] = array( + 'fields' => array( + 'fid' => array('type' => 'serial', 'not null' => TRUE), + 'event' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('fid'), + ); + + $schema['history'] = array( + 'fields' => array( + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('uid', 'nid'), + ); + + $schema['sequences'] = array( + 'fields' => array( + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('name'), + ); + + $schema['sessions'] = array( + 'fields' => array( + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'sid' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'cache' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'session' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big') + ), + 'primary key' => array('sid'), + 'indexes' => array( + 'timestamp' => array('timestamp'), + 'uid' => array('uid') + ), + ); + + $schema['system'] = array( + 'fields' => array( + 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'type' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'owner' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'throttle' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'bootstrap' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'schema_version' => array('type' => 'int', 'not null' => TRUE, 'default' => -1, 'size' => 'small'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'info' => array('type' => 'text', 'not null' => FALSE) + ), + 'primary key' => array('filename'), + 'indexes' => array('weight' => array('weight')), + ); + + $schema['url_alias'] = array( + 'fields' => array( + 'pid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'src' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'dst' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '') + ), + 'unique keys' => array('dst_language' => array('dst', 'language')), + 'primary key' => array('pid'), + 'indexes' => array('src' => array('src')), + ); + + $schema['variable'] = array( + 'fields' => array( + 'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'value' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), + 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '') + ), + 'primary key' => array('name', 'language'), + ); + + return $schema; +} + diff --git a/modules/taxonomy/taxonomy.schema b/modules/taxonomy/taxonomy.schema new file mode 100644 index 000000000..36d171251 --- /dev/null +++ b/modules/taxonomy/taxonomy.schema @@ -0,0 +1,100 @@ +<?php +// $Id$ + +function taxonomy_schema() { + $schema['term_data'] = array( + 'fields' => array( + 'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array('tid'), + 'indexes' => array('vid' => array('vid')), + ); + + $schema['term_hierarchy'] = array( + 'fields' => array( + 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'parent' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'parent' => array('parent'), + 'tid' => array('tid') + ), + 'primary key' => array('tid', 'parent'), + ); + + $schema['term_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) + ), + 'indexes' => array( + 'nid' => array('nid'), + 'tid' => array('tid'), + 'vid' => array('vid') + ), + 'primary key' => array( + 'vid', + 'tid', + 'nid' + ), + ); + + $schema['term_relation'] = array( + 'fields' => array( + 'trid' => array('type' => 'serial', 'not null' => TRUE), + 'tid1' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'tid2' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'tid1' => array('tid1'), + 'tid2' => array('tid2') + ), + 'primary key' => array('trid'), + ); + + $schema['term_synonym'] = array( + 'fields' => array( + 'tsid' => array('type' => 'serial', 'not null' => TRUE), + 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '') + ), + 'indexes' => array( + 'name' => array(array('name', 3)), + 'tid' => array('tid') + ), + 'primary key' => array('tsid'), + ); + + $schema['vocabulary'] = array( + 'fields' => array( + 'vid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big'), + 'help' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'relations' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'hierarchy' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'multiple' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'required' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'tags' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array('vid'), + ); + + $schema['vocabulary_node_types'] = array( + 'fields' => array( + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '') + ), + 'primary key' => array('vid', 'type'), + ); + + return $schema; +} + diff --git a/modules/user/user.schema b/modules/user/user.schema new file mode 100644 index 000000000..032778f10 --- /dev/null +++ b/modules/user/user.schema @@ -0,0 +1,85 @@ +<?php +// $Id$ + +function user_schema() { + $schema['access'] = array( + 'fields' => array( + 'aid' => array('type' => 'serial', 'not null' => TRUE), + 'mask' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'type' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny') + ), + 'primary key' => array('aid'), + ); + + $schema['authmap'] = array( + 'fields' => array( + 'aid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'authname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'module' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '') + ), + 'unique keys' => array('authname' => array('authname')), + 'primary key' => array('aid'), + ); + + $schema['permission'] = array( + 'fields' => array( + 'pid' => array('type' => 'serial', 'not null' => TRUE), + 'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'perm' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big'), + 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('pid'), + 'indexes' => array('rid' => array('rid')), + ); + + $schema['role'] = array( + 'fields' => array( + 'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'name' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => '') + ), + 'unique keys' => array('name' => array('name')), + 'primary key' => array('rid'), + ); + + $schema['users'] = array( + 'fields' => array( + 'uid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'name' => array('type' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => ''), + 'pass' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), + 'mail' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'default' => ''), + 'mode' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'sort' => array('type' => 'int', 'not null' => FALSE, 'default' => 0, 'size' => 'tiny'), + 'threshold' => array('type' => 'int', 'not null' => FALSE, 'default' => 0, 'size' => 'tiny'), + 'theme' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'signature' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'access' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'login' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'), + 'timezone' => array('type' => 'varchar', 'length' => 8, 'not null' => FALSE), + 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''), + 'picture' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'init' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'default' => ''), + 'data' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big') + ), + 'indexes' => array( + 'access' => array('access'), + 'created' => array('created') + ), + 'unique keys' => array('name' => array('name')), + 'primary key' => array('uid'), + ); + + $schema['users_roles'] = array( + 'fields' => array( + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('uid', 'rid'), + ); + + return $schema; +} + diff --git a/update.php b/update.php index adfce749c..feb970a7f 100644 --- a/update.php +++ b/update.php @@ -17,12 +17,6 @@ // Enforce access checking? $access_check = TRUE; - -function update_sql($sql) { - $result = db_query($sql); - return array('success' => $result !== FALSE, 'query' => check_plain($sql)); -} - /** * Add a column to a database using syntax appropriate for PostgreSQL. * Save result of SQL commands in $ret array. |