[development] Foreign keys in Drupal 6

David Strauss david at fourkitchens.com
Mon Jun 4 03:14:53 UTC 2007

Assuming the foreign keys patch to the schema API makes it in, there are
four ways we can approach foreign keys in Drupal 6.

1. Don't use them at all. Just provide the schema API for contrib
modules with higher database requirements than core.

2. Configure foreign keys as RESTRICT on delete. This will have no
effect on MyISAM, but it will improve code quality because operations
creating inconsistency would fail. Such operations would then be
rewritten to manipulate the database in a consistent way.

3. Configure foreign keys as CASCADE on delete and have extra PHP run
whenever a query manipulates a database using MyISAM. Basically,
whenever a DELETE query gets sent to a MyISAM system, we would convert
it to a SELECT query to identify the rows that would be deleted. Then,
we would delete the records attached with foreign keys. Finally, we
would run the original DELETE query. This would have to be recursive.

4. Configure foreign keys as CASCADE on delete and have modules
conditionally run queries in their deletion hooks depending on the
storage engine. If a module doesn't check the storage engine type, the
DELETE it runs would simply be redundant.

Personally, I think #2 would be a nice first step in Drupal 6. It would
at least force us to clean up the database interaction so #3 or #4 could
be seamlessly added later.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 186 bytes
Desc: OpenPGP digital signature
Url : http://lists.drupal.org/pipermail/development/attachments/20070603/146cbb19/attachment.pgp 

More information about the development mailing list