Two hook_schema() implementations define foreign key constraints referring to tables which are defined later in the same hook_schema() implementation. This makes using foreign key constraints difficult. The attached patch re-arranges the order that the tables are defined in inside the two hook_schema() implementations. This fixes and the problem and should have no side-effects.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Liam Morland’s picture

FileSize
11.33 KB

Reroll.

Liam Morland’s picture

FileSize
11.38 KB

Reroll.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

pretty straightforward, just rearranging code

webchick’s picture

Assigned: Unassigned » jhodgdon
Category: bug » task
Status: Reviewed & tested by the community » Fixed

Confirmed this is just moving some code around.

Committed and pushed to 8.x. Thanks!

webchick’s picture

Assigned: jhodgdon » Unassigned

Oops. :)

sun’s picture

1) There are no references in functional code between schema definitions. The order of definition does not matter at all.

2) If any "order" can and should be applied, then that order is alphabetical. Which apparently was the case for most hook_schema() definitions already. This change broke that.

3) This change could have used some more reviews before commit. Especially since it requires a couple of major patches in the queue to be rerolled.

Liam Morland’s picture

The order does matter if foreign key constraints are being created. Foreign key constraints can only refer to tables that already exist. The reorder in this patch ensured that tables only refer to other tables that already exist.

This patch helps with #911352: Document that foreign keys may not be used by all drivers.

webchick’s picture

Right, and even if it didn't help with that patch (which I'm still not totally convinced we should do in core), it does help with the understanding of the database schema for a first-time reader. Alphabetical is a totally arbitrary way to outline schema definitions; "natural order" (where you learn what a vocabulary is *before* you see references to it in other tables) makes a lot more sense.

If you have major patches that are close to RTBC which you don't want to be broken by cleanup patches, we have a process for that; tag them "Avoid commit conflicts." there are no patches that touch taxonomy.install in the list.

Liam Morland’s picture

@webchick: That is a good way of explaining it. Creating tables before referring to them makes sense for people as well as computers.

Status: Fixed » Closed (fixed)

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