In the "making our database squeaky-clean" department:

The core schema has default values all over the place that make no sense. For example:

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' => FALSE, 'default' => 0),
      'type'      => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),

node.type can never correctly be the empty string. node.vid can never correctly be 0. It is possible that node.vid needs to be 0 or some other temporary value while the node_revisions row is being created (since either node or node_revisions needs to come first, one column will always need a temp value), but that still doesn't mean that a "default value" of 0 is correct.

Having these incorrect default values works fine, of course, but it is semantically misleading. I'm pretty sure many of them are there because of MySQL's rather broken (IMHO) "implicit default values" behavior (http://drupal.org/node/159330) to make otherwise invaid queries work on pgsql.

Cleaning this up is straightforward. Remove the invalid default values, and any INSERT queries that rely on them will pop out during pgsql testing; they are then easy to fix. I suggest that these be considered bugs and fixed for D6, but if someone wants to tell me this is inappropriate during code freeze, I'm fine with pushing this to D7.

Comments

bjaspan’s picture

Version: 6.x-dev » 7.x-dev

This won't happen for D6.

Crell’s picture

Version: 7.x-dev » 8.x-dev

Nor in D7, apparently. Ah well.

pillarsdotnet’s picture

Status: Active » Needs review
StatusFileSize
new62.27 KB

Patch

Status: Needs review » Needs work

The last submitted patch, schema-remove_incorrect_defaults-159346-6.patch, failed testing.

tr’s picture

The patch shouldn't modify openid_update_6000(), and it should provide hook_update_N() for all the modules whose schema you've changed by removing the default.

pillarsdotnet’s picture

(sigh)

pfrenssen’s picture

Most of the changes to the defaults seem good, but I'm not sure about defaulting user.status to 1. I agree to remove system.update for D8, the chance that this is actually carried over from a D5 install and still has meaning is quite negligible, but then again maybe that's another issue.

I agree with #8 that openid_update_6000() should remain intact, but is it really necessary to write hook_updates for all tables to remove the defaults?

pillarsdotnet’s picture

@pfrenssen

is it really necessary to write hook_updates for all tables to remove the defaults?

Unfortunately, yes. Which would make this huge patch many times larger. Which is why I pretty-much abandoned this issue as being more work than it's worth.

kattekrab’s picture

Perhaps time to move this one to D9 as well?

stewartsmith’s picture

Also consider enabling strict_mode SQL_MODE in MySQL - this will help you catch a bunch of these things and likely improve portability to other RDBMSs that are a little more strict/correct than MySQL is.

Crell’s picture

stewartsmith: MySQL strict mode has been enabled since the early days of the Drupal 7 dev cycle, vis, about 5 years now.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Issue tags: +Bug Smash Initiative

On the positive side there are only 19 install files that declare 'default' instead of 29, which is in the latest patch here.

$ grep -r "'default' => " core/modules/*/*.install | awk -F: '{print $1}' | sort -u | nl
     1  core/modules/ban/ban.install
     2  core/modules/book/book.install
     3  core/modules/comment/comment.install
     4  core/modules/dblog/dblog.install
     5  core/modules/file/file.install
     6  core/modules/forum/forum.install
     7  core/modules/help_topics/help_topics.install
     8  core/modules/history/history.install
     9  core/modules/layout_builder/layout_builder.install
    10  core/modules/locale/locale.install
    11  core/modules/migrate_drupal/migrate_drupal.install
    12  core/modules/node/node.install
    13  core/modules/search/search.install
    14  core/modules/shortcut/shortcut.install
    15  core/modules/statistics/statistics.install
    16  core/modules/system/system.install
    17  core/modules/tracker/tracker.install
    18  core/modules/user/user.install
    19  core/modules/workspaces/workspaces.install

I hope to remember to bring this issue up at the next Bug Smash initiative meeting.

quietone’s picture

Version: 8.9.x-dev » 9.3.x-dev
Category: Bug report » Task

This came up in #bugsmash. larowlan thinks it is a task. I agree.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

And now there are 13 files

$ grep -r "'default' => " core/modules/*/*.install | awk -F: '{print $1}' | sort -u | nl
     1  core/modules/ban/ban.install
     2  core/modules/comment/comment.install
     3  core/modules/dblog/dblog.install
     4  core/modules/file/file.install
     5  core/modules/help/help.install
     6  core/modules/history/history.install
     7  core/modules/layout_builder/layout_builder.install
     8  core/modules/locale/locale.install
     9  core/modules/node/node.install
    10  core/modules/search/search.install
    11  core/modules/shortcut/shortcut.install
    12  core/modules/user/user.install
    13  core/modules/workspaces/workspaces.install

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.