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

Comments

Gribnif’s picture

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.

Gribnif’s picture

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]);
Alan D.’s picture

Status:Active» 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!

mikeryan’s picture

I think I'm missing something here - what exactly is the condition and effect being fixed? I've tried throwing a 'default' => NULL into a column definition, and compare is not reporting a mismatch... On $col['default'], isset() returns FALSE and is_null() returns TRUE regardless of the presenece of 'default' => NULL.

attheshow’s picture

Title:Compairson mismatch when default is NULL» Comparison mismatch when default is NULL

Correcting typo in title.

Alan D.’s picture

I no longer am able to replicate this - the install that was showing the issue has been cleaned up of all developmental modules and is in production. The above patch / code snippet fixed the problem back then, and I'm happy to close this to clean up the issue queue.

mikeryan’s picture

Status:Needs review» Closed (won't fix)

Not reproducible, closing out. If someone can describe specifically how to reproduce this issue, please reopen with details.

mizerydearia’s picture

I believe my issue is related to this discussion:

admin/build/schema/compare
uc_power_tools.asku-settings is type text and may not have a default value
Mismatch (1)
Tables for which the schema and database are different: uc_power_tools
column asku-settings - differences on: not null, default
declared: array('description' => t('TODO: please describe this field!'), 'type' => 'text', 'not null' => FALSE, 'default' => '')
actual: array('description' => t('TODO: please describe this field!'), 'type' => 'text', 'not null' => FALSE)

I wasn't sure how to fix this problem, but I discovered that with phpmyadmin, manipulating the structure of the uc_power_tools table was the solution.
Field asku-settings in phpmyadmin shows Null: Yes, Default: Null
I believe the Default: Null is the mismatch with the expectancy of Default: '' (excluding the apostrophes, representing an empty string)
However, when editing or changing the field settings for asku-settings within phpmyadmin, when removing "NULL" from the text input for Default, so as to change it to an empty string, SQL outputs query of:
ALTER TABLE `uc_power_tools` CHANGE `asku-settings` `asku-settings` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL
Success!?!?
Nope. While the SQL query was success, the asku-settings Default is still NULL.

How can I fix this? Any ideas?

mizerydearia’s picture

Version:6.x-1.3» 6.x-1.2
Status:Closed (won't fix)» Needs review

I didn't figure out how to fix the database to the declared value, howver, I was able to fix the declared value to match the database and fix my issue.

I modified file uc_product_power_tools.install, line 188
from 'default' => '',
to 'default' => NULL,

fixed!

Also, I am using uc_product_power_tools 6.x-1.2, not 6.x-1.3
I haven't noticed any update requirements from admin/reports/updates and reviewing that page, I don't even see any entry for Product Power Tools. Thus, I didn't realize there was an update available.

I see at http://drupal.org/project/uc_product_power_tools that apparently 6.x-1.10 is latest version available. That is far beyond 6.x-1.2 I shall manually update from my version for now. I'm glad I noticed this. Perhaps the current version will better integrate with Drupal so that this module informs users if there are updates.

UPDATE:

I updated to version 6.x-1.10 and applied database updates and now:

    * column asku - difference on: not null
      declared: array('description' => t('TODO: please describe this field!'), 'type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => FALSE, 'default' => 0)
      actual: array('description' => t('TODO: please describe this field!'), 'type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)
    * column weight - differences on: scale, precision
      declared: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
      actual: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'precision' => '', 'scale' => '')
    * column length - differences on: scale, precision
      declared: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
      actual: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'precision' => '', 'scale' => '')
    * column width - differences on: scale, precision
      declared: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
      actual: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'precision' => '', 'scale' => '')
    * column height - differences on: type, scale, precision
      declared: array('description' => t('TODO: please describe this field!'), 'type' => 'numeric', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'precision' => 15, 'scale' => 3)
      actual: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'precision' => '', 'scale' => '')

I am not sure how to fix the scale/precision differences. I do not see where or what they are in the database through phpmyadmin 2.11.9.5 interface.

Ugh! I think I confused Schema and uc_product_power_tools as well as posted to wrong node.

mikeryan’s picture

Status:Needs review» Closed (fixed)

Previous post mistakenly reopened this issue.