Compairson mismatch when default is NULL

Alan D. - May 10, 2008 - 02:46
Project:Schema
Version:6.x-1.3
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:patch (code needs review)
Description

Just wondering if schema definitions using default=>NULL pass the comparison tests.

For example:

<?php
  $schema
['family'] = array(
   
'fields' => array(
     
'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'normal'),
     
'family_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => NULL, 'size' => 'normal', 'disp-width' => '10'),
    ),
   
'primary key' => array('id'),
   
'indexes' => array(
     
'family_id' => array('family_id'),
    ),
  );
?>

Regards
Alan

#1

Gribnif - June 17, 2008 - 21:30

Saying 'default' => NULL is optional, as this is the default condition. But the schema module doesn't currently take this into consideration. Here's a patch which corrects this.

#2

Gribnif - June 17, 2008 - 21:32

Alright, I don't know what's happening to my attempts at uploading an attachment. Here it is, pasted in.

--- schema.module.orig 2008-06-17 17:22:44.000000000 -0400
+++ schema.module 2008-06-17 17:23:19.000000000 -0400
@@ -323,6 +323,10 @@ function schema_compare_table($ref, $ins
       $reasons[] = "$colname: not in database";
       continue;
     }
+    // Account for schemas that contain unnecessary 'default' => NULL
+    if (is_null($col['default']) && !isset($inspect['fields'][$colname]['default'])) {
+      unset($col['default']);
+    }
     // XXX These should be unified so one reason contains all
     // mismatches between the columns.
     $colcmp1 = array_diff_assoc($col, $inspect['fields'][$colname]);

#3

Alan D. - June 19, 2008 - 11:08
Status:active» patch (code needs review)

Thanks.

Looking forward seeing it in core, ... hopefully with native Drupal NULL support now things are finally getting wrapped with PDO abstraction layer!

 
 

Drupal is a registered trademark of Dries Buytaert.