Tripal
|
Public Member Functions | |
getSchemaDef (array $parameters) | |
__construct (\Drupal\tripal\TripalDBX\TripalDbxConnection $connection) | |
initialize () | |
getSchemaName () | |
findTables ($table_expression) | |
queryTableInformation ($table) | |
indexExists ($table, $index_name, bool $exact_name=FALSE) | |
getSchemaSize () | |
schemaExists () | |
functionExists (string $function_name, array $function_parameters) | |
sequenceExists (?string $table_name=NULL, ?string $column_name=NULL, ?string &$sequence_name=NULL) | |
constraintExists ( $table, $constraint_name, ?string $type=NULL) | |
primaryKeyExists (string $table, ?string $column=NULL) | |
foreignKeyConstraintExists (string $base_table, string $base_column) | |
getTables (array $include=[]) | |
getTableDef (string $table, array $parameters) | |
getTableDdl (string $table_name, bool $clear_cache=FALSE) | |
getReferencingTables (string $table_name, bool $clear_cache=FALSE) | |
createSchema () | |
cloneSchema (string $source_schema) | |
renameSchema (string $new_schema_name) | |
dropSchema () | |
tableExists ($table) | |
Protected Attributes | |
$defaultSchema = '' | |
$quotedDefaultSchema = '' | |
$initialized = FALSE | |
$tripalDbxApi = NULL | |
Tripal DBX API Schema class.
NOTE: This class should not be instantiated directly but rather it should be accessed through a TripalDbxConnection object using the schema() method.
This class provides a Tripal-specific implementation of the Drupal Schema abstract class. The Drupal PostgreSQL (and other database driver) implementations of the base Drupal Schema class follow the assumption that there is a single schema. As such the core Drupal implementations focus on managing tables within a single schema.
This implementation extends that table-management functionality to also include Schema-focused management including creation, cloning, renaming, dropping and definition export. Additionally, it removes the assumption of a single schema by allowing the default schema to be set based on a Tripal DBX connection.
Here are some useful functions to know that are inherited from Drupal Schema classes (core + PgSchema implementation):
Drupal\tripal\TripalDBX\TripalDbxSchema::__construct | ( | \Drupal\tripal\TripalDBX\TripalDbxConnection | $connection | ) |
Constructor.
OVERRIDES \Drupal\Core\Database\Schema:__construct().
Overrides default constructor to manage the Tripal DBX managed schema name.
The TripalDbxSchema object should be instantiated by the TripalDbxConnection::schema() method in order to avoid issues when the default Tripal DBX managed schema name is changed in the TripalDbxConnection object which could lead to issues.
If you choose to instantiate a TripalDbxSchema object yourself, you are responsible to not change the Tripal DBX managed schema name of the connection object used to instantiate this TripalDbxSchema.
\Drupal\tripal\TripalDBX\TripalDbxConnection | $connection | A Tripal DBX connection object. |
Drupal\tripal\TripalDBX\TripalDbxSchema::cloneSchema | ( | string | $source_schema | ) |
Clones a schema into new (unexisting) one.
The target schema must not exist. If $target_schema is omitted, current schema will be used. For instance, if you want to clone "chado" schema into a "chado_copy" schema, you would do something like this:
string | $source_schema | Source schema to clone. |
?string | $target_schema Destination schema that will be created and filled with a copy of $source_schema. If not set, current schema will be the target. |
Drupal\tripal\TripalDBX\TripalDbxSchema::constraintExists | ( | $table, | |
$constraint_name, | |||
?string | $type = NULL |
||
) |
Check that the constraint exists.
OVERRIDES \Drupal\Core\Database\Schema:constraintExists().
Our version of this method adds an optional parameter $type to support type-specific searching and exact name matches since many biological data-focused databases will not follow the Drupal naming patterns. For example, Chado does not follow these patterns.
string | $table | The table the constraint applies to. |
string | $constraint_name | The name of the constraint you want to check. |
?string | $type The type of constraint. Should be one of "PRIMARY KEY", "UNIQUE", or "FOREIGN KEY". |
Drupal\tripal\TripalDBX\TripalDbxSchema::createSchema | ( | ) |
Creates the given schema.
The schema to create must not exist. If an error occurs, an exception is thrown.
Drupal\tripal\TripalDBX\TripalDbxSchema::dropSchema | ( | ) |
Removes the given schema.
The schema to remove must exist. If an error occurs, an exception is thrown.
Drupal\tripal\TripalDBX\TripalDbxSchema::findTables | ( | $table_expression | ) |
Finds all tables that are like the specified base table name.
OVERRIDES \Drupal\Core\Database\Schema:findTables().
NOTE: In Drupal 10 individually prefixed tables will no longer be supported. At this point we should re-evaluate if this override is still needed.
Overrides the PostgreSQL implementation for two reasons:
string | $table_expression | An SQL expression, for example "cache_%" (without the quotes). |
Drupal\tripal\TripalDBX\TripalDbxSchema::foreignKeyConstraintExists | ( | string | $base_table, |
string | $base_column | ||
) |
Check the foreign key constrain specified exists.
string | $base_table | The name of the table the foreign key resides in. E.g. 'feature' for the feature.type_id => cvterm.cvterm_id foreign key. |
string | $base_column | The name of the column that is a foreign key in. E.g. 'type_id' for the feature.type_id => cvterm.cvterm_id foreign key. |
Drupal\tripal\TripalDBX\TripalDbxSchema::functionExists | ( | string | $function_name, |
array | $function_parameters | ||
) |
Check that the given function exists.
Example:
string | $function_name | The name of the function. |
array | $func_parameters | An ordered array of input parameter types that are part of the function signature. |
Drupal\tripal\TripalDBX\TripalDbxSchema::getReferencingTables | ( | string | $table_name, |
bool | $clear_cache = FALSE |
||
) |
Retrieves tables referencing a given one.
string | $table | The name of the table used as foreign table by other tables. |
bool | $clear_cache | If TRUE, cache is cleared. |
|
abstract |
Retrieve schema details from selected source in the requested format.
array | $parameters | An array of key-value parameters:
|
Reimplemented in Drupal\tripal_chado\Database\ChadoSchema, and Drupal\Tests\tripal\Kernel\TripalDBX\Subclass\TripalDbxSchemaFake.
Drupal\tripal\TripalDBX\TripalDbxSchema::getSchemaName | ( | ) |
Returns current schema name.
Drupal\tripal\TripalDBX\TripalDbxSchema::getSchemaSize | ( | ) |
Returns the size in bytes of a PostgreSQL schema.
Drupal\tripal\TripalDBX\TripalDbxSchema::getTableDdl | ( | string | $table_name, |
bool | $clear_cache = FALSE |
||
) |
Retrieves the table DDL (table data definition language).
string | $table | The name of the table to retrieve. |
bool | $clear_cache | If TRUE, cache is cleared. |
Drupal\tripal\TripalDBX\TripalDbxSchema::getTableDef | ( | string | $table, |
array | $parameters | ||
) |
Returns the specified table structure details.
string | $table | The name of the table. |
array | $parameters | An array of key-value parameters:
|
Drupal\tripal\TripalDBX\TripalDbxSchema::getTables | ( | array | $include = [] | ) |
Retrieves the list of tables in the given schema.
Note: only peristant tables (ie. no unlogged or temporary tables) visible by current DB user are returned.
array | $include | An associative array to select other element type to include. Supported keys are: 'table': include all tables; 'base': include only base tables (as defined in the original Tripal Dbx schema definition); 'custom': include only custom tables (not part of the original Tripal Dbx schema definition); 'view': include views; 'partition': include partitions; 'materialized view': include PostgreSQL materialized views (not to be confused with Tripal materialized views which currently are regular tables); If both 'base' and 'custom' are specified, all tables are returned. Default: tables only (empty array). |
Drupal\tripal\TripalDBX\TripalDbxSchema::indexExists | ( | $table, | |
$index_name, | |||
bool | $exact_name = FALSE |
||
) |
Checks if an index exists in the given table.
OVERRIDES \Drupal\Core\Database\Schema:indexExists().
Our version of this method adds an optional parameter $exact_name to support exact name matches since many biological data-focused databases will not follow the Drupal index naming pattern. For example, Chado does not follow this pattern.
$table | The name of the table in Tripal DBX managed schema. | |
$name | The full name of the index (including the '_idx' part for instance). | |
bool | $exact_name | If FALSE, Drupal will append to the given name the '__idx' suffix (added when ::addIndex is used) and will adjust the name if needed (length). If TRUE, the function assumes the given index name is complete. |
Drupal\tripal\TripalDBX\TripalDbxSchema::primaryKeyExists | ( | string | $table, |
?string | $column = NULL |
||
) |
Check that the primary key exists, has a sequence and a constraint.
string | $table | The table you want to check the primary key for. |
?string | $column (optional) The name of the primary key column. |
Drupal\tripal\TripalDBX\TripalDbxSchema::queryTableInformation | ( | $table | ) |
Fetch the list of blobs and sequences used on a table.
OVERRIDES \Drupal\Core\Database\Schema:queryTableInformation().
Override is required for proper table prefixing. While the exact mechanism isn't clear, if this function is removed then tests will fail due to incorrect table prefixing.
string | $table_name | The non-prefixed name of the table. |
Drupal\tripal\TripalDBX\TripalDbxSchema::renameSchema | ( | string | $new_schema_name | ) |
Renames a schema.
The new schema name must not be used by an existing schema. If an error occurs, an exception is thrown.
string | $new_schema_name | New name to use. |
Drupal\tripal\TripalDBX\TripalDbxSchema::schemaExists | ( | ) |
Check that the given schema exists.
Drupal\tripal\TripalDBX\TripalDbxSchema::sequenceExists | ( | ?string | $table_name = NULL , |
?string | $column_name = NULL , |
||
?string & | $sequence_name = NULL |
||
) |
Check that any given sequence in a table exists.
When the sequence name is not known, a table name and a column name can be specified instead. Then, the sequence name will be guessed from those and returned into the given $sequence_name variable if provided. If both the sequence name and the table and column names are specified, only the sequence name will be taken into account.
This information can also be extracted from ::queryTableInformation()['sequences'].
string | $table_name | The name of the table the sequence is used in. |
string | $column_name | The name of the column the sequence is used to populate. |
string | &$sequence_name | The name of the sequence is to check if known. Otherwise, the function will set it. |
Drupal\tripal\TripalDBX\TripalDbxSchema::tableExists | ( | $table | ) |
Overrides Drupal\Core\Database\Schema->tableExists().
We needed to override it because core Drupal makes some assumptions when building the where condition that do not match our multi-schema setup.