tripal / t4d8

This is a temporary repository for Drupal 9 upgrade for Tripal v4. It is meant to house issues related to the upgrade.
GNU General Public License v2.0
1 stars 10 forks source link

Test Tripal DBX Table Prefixing + Add support for Inheritance #290

Closed laceysanderson closed 1 year ago

laceysanderson commented 1 year ago

This PR tests Tripal DBX table prefixing and was undertaken to address Issue #217.

It turns out that Tripal DBX table prefixing is not actually broken and this is more a misunderstanding and incorrect usage. As such, I have documented how Tripal DBX determines the table prefix to apply in Tripal Doc Issue 9.

To summarize, if the schema to use is not indicated (i.e. if you use {tablename} rather then {1:tablename}) then Tripal DBX automatically assumes you want the Drupal database. This is needed since Drupal seems to unknowingly use Tripal DBX sometimes (why needs more exploration). In order to allow queries using {chadotable} you need to add the class executing these queries to a Tripal DBX managed whitelist. This is done as follows:

$connection = \Drupal::service('tripal_chado.database');
// Pass in the current class name
$connection->useTripalDbxSchemaFor(get_class());
// Pass in a specific class
$connection->useTripalDbxSchemaFor(\Drupal\tripal_chado\TripalImporter\ChadoImporterBase::class);
// Pass in the current object.
$connection->useTripalDbxSchemaFor($this);

NOTE: I'm still confirming but it is likely this whitelist is specific to the current connection instance.

Additionally, I added automated testing to confirm this functionality and to ensure it continues to work.

I also added functionality to check through the inheritance chain to allow us to specify parent classes and added additional in class documentation to the TripalDbxConnection class.

codeclimate[bot] commented 1 year ago

Code Climate has analyzed commit d03501a7 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 20.5% (0.1% change).

View more on Code Climate.