function schema_compare_schemas in Schema 5
Same name and namespace in other branches
- 8 schema.module \schema_compare_schemas()
- 6 schema.module \schema_compare_schemas()
- 7 schema.module \schema_compare_schemas()
2 calls to schema_compare_schemas()
- schema_report in ./schema.module
- schema_requirements in ./schema.install
File
- ./schema.module, line 187
Code
function schema_compare_schemas($ref, $inspect = NULL) {
if (!isset($inspect)) {
$inspect = schema_invoke('inspect');
}
$info = array();
foreach ($ref as $t_name => $table) {
foreach ($table['fields'] as $c_name => $col) {
switch ($col['type']) {
case 'int':
case 'float':
case 'numeric':
if (isset($col['default']) && (!is_numeric($col['default']) || is_string($col['default']))) {
$info['warn'][] = t('%table.%column is type %type but its default %default is PHP type %phptype', array(
'%table' => $t_name,
'%column' => $c_name,
'%type' => $col['type'],
'%default' => $col['default'],
'%phptype' => gettype($col['default']),
));
}
break;
default:
if (isset($col['default']) && !is_string($col['default'])) {
$info['warn'][] = t('%table.%column is type %type but its default %default is PHP type %phptype', array(
'%table' => $t_name,
'%column' => $c_name,
'%type' => $col['type'],
'%default' => $col['default'],
'%phptype' => gettype($col['default']),
));
}
break;
}
}
}
foreach ($ref as $t_name => $table) {
foreach ($table['fields'] as $c_name => $col) {
switch ($col['type']) {
case 'text':
case 'blob':
if ($table['module'] != 'core' && isset($col['default'])) {
$info['warn'][] = t('%table.%column is type %type and may not have a default value', array(
'%table' => $t_name,
'%column' => $c_name,
'%type' => $col['type'],
));
}
break;
}
}
}
foreach ($ref as $t_name => $table) {
if (isset($table['primary key'])) {
$keys = db_field_names($table['primary key']);
foreach ($keys as $key) {
if (!isset($table['fields'][$key]['not null']) || $table['fields'][$key]['not null'] != TRUE) {
$info['warn'][] = t('%table.%column is part of the primary key but is not specified to be \'not null\'.', array(
'%table' => $t_name,
'%column' => $key,
));
}
}
}
}
foreach ($ref as $name => $table) {
$module = $table['module'];
if (!isset($inspect[$name])) {
$info['missing'][$module][$name] = array(
'status' => 'missing',
);
}
else {
$status = schema_compare_table($table, $inspect[$name]);
$info[$status['status']][$module][$name] = $status;
unset($inspect[$name]);
}
}
foreach ($inspect as $name => $table) {
$info['extra'][] = $name;
}
return $info;
}