Luckily Schema module complains:
* search_dataset.type is part of the primary key but is not specified to be 'not null'.
* search_index.type is part of the primary key but is not specified to be 'not null'.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Status: Needs review » Postponed (maintainer needs more info)

This patch is incomplete - if we do change this, there would also need to be an update function that would alter the fields to be NOT NULL.

That detail aside, I'm not an expert on the details of NOT NULL and primary keys... Obviously, MySQL (and probably PostgreSQL too) must be letting these tables be created with their primary keys and fields as they are, for most people, or we would have had tons of bug reports about this starting in Drupal 6 (the schema has not changed since then, at least in this regard). Why is Luckily Schema complaining?

jhodgdon’s picture

Status: Postponed (maintainer needs more info) » Needs work

Ah, here is some more information:

http://dev.mysql.com/doc/refman/5.1/en/create-table.html

A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. If you do not have a PRIMARY KEY and an application asks for the PRIMARY KEY in your tables, MySQL returns the first UNIQUE index that has no NULL columns as the PRIMARY KEY.

So, agreed: we should probably change this. Needs a new patch though, since there should be an upgrade function.

Damien Tournoud’s picture

We don't actually need the update function if MySQL did that already silently.

Stevel’s picture

Status: Needs work » Needs review

The fields are effectively created as NOT NULL already because of the primary key definition. This is what creates the mismatch between the schema definition and the actual tables. This also means an update function would not make any change change the database, making it unnecessary. Setting to needs review again.

"Why is Luckily Schema complaining?"
I just mean that it's a good thing that the Schema module complains about this :)

Stevel’s picture

Status: Needs review » Needs work

Aha, a field not marked as NOT NULL gets a default of '' (empty string), so we need an update function to remove this default.

Rerolling in an minute...

Stevel’s picture

Status: Needs work » Needs review
FileSize
2.4 KB

New version of the patch, which modifies the update function that creates the primary key.

Status: Needs review » Needs work

The last submitted patch, 853896-remove-default.patch, failed testing.

Stevel’s picture

Status: Needs work » Needs review
FileSize
1.79 KB

Removed the ANSI coloring from the patch, no wonder it didn't apply :)

jhodgdon’s picture

OK. I guess since we are not trying to maintain HEAD to HEAD updates (I think we aren't anyway), editing an existing update function is probably OK. Once we are trying to maintain updates between 7.x versions, of course, we would need to add a new update function to do this.

Regarding the need for an update function in general in this case, I only investigated MySQL, and found that documentation about it silently setting the field to not null = TRUE. I am not sure what happens for PostgreSQL, SQLite, etc. So I do think the update function is a good idea, and I'm glad you had a different reason for thinking it was a good idea too.

Anyway, I guess I'm OK with this patch. Someone else want to RTBC it?

jhodgdon’s picture

#8: 853896-remove-default.patch queued for re-testing.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

This should be fairly non-controversial...

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.