It would be useful to be able to adopt tables in the database that aren't managed by another module (that is, described via the SchemaAPI). Here is a patch to enable table adoption through data_ui; it depends on the Schema module.

I am not sure if there is some way I should be using the DataTable class, but it seems like all the methods assume you're either creating a fresh table, or that you're working with a table that Data already knows about.

Comments

alex_b’s picture

Status: Needs review » Needs work

This is awesome.

Couple of things:

- I love the verbiage.
- Move the adopt logic from data_ui_adopt_form_submit() into DataTable::adopt($name, $table_schema).
- Add a help text to the adopt page and add an empty text for the case when there are no orphaned tables detected http://skitch.com/alexbarth/nr9fk/data-tables-localhost
- data_ui_adopt_form_submit() needs a comment.

becw’s picture

Status: Needs work » Needs review
StatusFileSize
new5.61 KB

Thanks for the feedback :) I added an 'adopt' method to the DataTable class, help text, and fresh comments.

alex_b’s picture

StatusFileSize
new6.71 KB

You ran headlong into an issue I wanted to address earlier. The fact that putting clearing caches into CRUD functions isn't efficient if these functions are being batched.

The way how I'd like to address this is having no cache clear / rebuild functionality in CRUD methods at all and make it the API user's responsibility to clear caches after operations. I added DataTable::cacheClear() and modified the adopt patch accordingly as a first step in the right direction.

Other changes:

- Passing in the table name into adopt is redundant
- Minor tweaks to naming conventions to keep consistent with rest of code (i. e. call table $table, not $tmp. Nitty gritty stuff)
- unset() table pointer after adopting the table.
- Make $schema an optional parameter for adopt() so that API users can rely on DataTable to inspect the table. This keeps adopt() more in the pattern of create().

Needs review.

becw’s picture

StatusFileSize
new6.27 KB

ooh, this looks good! I was wondering about a clearCaches() method because as you note I did run headlong into it. Two questions:

(1) Given that DataTable::adopt() assumes we will always be adopting the $this->name table, why take the $table_schema as an argument at all? Is passing in the table schema redundant as well? I'm attaching a version of the patch that doesn't use the $table_schema argument...

(2) With DataTable::clearCaches() now available, should cache clearing code be removed from DataTable::create() and DataTable::addField(), and then clearCaches() be called by either data_create_table() or the form submit functions in data_ui? I suspect that this might influence other code out there, and that perhaps it can and should be addressed after this, in another patch/issue.

alex_b’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new6.33 KB

1) Yes, good point.

2) Right, this would be a separate issue, just created one #618064: Remove cache clearing code from DataTable CRUD methods

Minor cleanup: adopt() does not need a table name as parameter any more. Removed it from call.

This is RTBC I'd say.

alex_b’s picture

Status: Reviewed & tested by the community » Fixed

Committed to DRUPAL-6--1. Thanks for the contribution, this is a great feature.

becw’s picture

Yay, thank you!

Status: Fixed » Closed (fixed)

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