Tripal
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
Drupal\tripal_chado\Task\ChadoApplyMigrations Class Reference
Inheritance diagram for Drupal\tripal_chado\Task\ChadoApplyMigrations:
Inheritance graph
[legend]
Collaboration diagram for Drupal\tripal_chado\Task\ChadoApplyMigrations:
Collaboration graph
[legend]

Public Member Functions

 setTripalJob (TripalJob $job)
 
 setInstallID (int $install_id)
 
 lookupInstallID ()
 
 reportMigrationStatus (object $migration, bool $status)
 
 checkMigrationStatus ()
 
 validateParameters ()
 
 performTask ()
 
 getProgress ()
 
 getStatus ()
 
- Public Member Functions inherited from Drupal\tripal_chado\Task\ChadoTaskBase
 getTripalDbxClass ($class)
 
- Public Member Functions inherited from Drupal\tripal_biodb\Task\BioTaskBase
 __construct (?Connection $database=NULL, ?LoggerInterface $logger=NULL, ?SharedLockBackendInterface $locker=NULL, ?StateInterface $state=NULL,)
 
 setParameters (array $parameters=[])
 
 getId ()
 
 getLogger ()
 

Static Public Member Functions

static runTripalJob (string $schema_name, int $install_id, TripalJob $job)
 
static getHighestVersion ()
 
static getAvailableMigrations ()
 

Public Attributes

const TASK_NAME = 'apply_migrations'
 
const BASELINE_CHADO_VERSION = '1.3'
 
const MIGRATIONS_INFO_YAML = '/chado_schema/migrations/tripal_chado.chado_migrations.yml'
 
const MIGRATION_DIR = '/chado_schema/migrations/'
 
array $migration_status = []
 
ChadoConnection $chado_connection
 
 $drupal_connection
 
- Public Attributes inherited from Drupal\tripal_chado\Task\ChadoTaskBase
const TASK_NAME = 'chado'
 
- Public Attributes inherited from Drupal\tripal_biodb\Task\BioTaskBase
const TASK_NAME = 'task'
 
const STATE_KEY_DATA_PREFIX = 'tripal_biodb_'
 

Protected Attributes

TripalJob $job
 
int $job_id = 0
 
int $install_id
 
int $version_cvterm_id
 
- Protected Attributes inherited from Drupal\tripal_biodb\Task\BioTaskBase
 $id
 
 $connection
 
 $logger
 
 $locker
 
 $state
 
 $parameters = ['input_schemas' => [], 'output_schemas' => []]
 
 $inputSchemas = []
 
 $outputSchemas = []
 

Additional Inherited Members

- Protected Member Functions inherited from Drupal\tripal_biodb\Task\BioTaskBase
 prepareSchemas (array $schema_list)
 
 getSchemaLockName (TripalDbxConnection $db,)
 
 initId ()
 
 acquireTaskLocks ()
 
 releaseTaskLocks ()
 

Detailed Description

Applies Chado Migrations usually handled by Flyway.

Usage:

// Where 'chado' is the name of the Chado schema to apply migrations to.
$flyway = \Drupal::service('tripal_chado.apply_migrations');
$flyway->setParameters([
'input_schemas' => ['chado'],
]);
if (!$flyway->performTask()) {
// Display a message telling the user the task failed and details are in
// the site logs.
}

Member Function Documentation

◆ checkMigrationStatus()

Drupal\tripal_chado\Task\ChadoApplyMigrations::checkMigrationStatus ( )

Checks the status of this schema. Specifically, which migrations have been applied and which are still pending.

Returns
array The key of this array is the migration version number and each element is an object with the following keys:
  • version: a string of the form '1.3.3.002'.
  • install_id: the ID of the chado installation as managed by tripal.
  • schema_name: the name of the schema the status applies to.
  • description: a short description of the migration.
  • applied_on: the date the migration was applied on.
  • success: an integer indicating the success of applying the migration. If successful, it will be '1' and otherwise, '0'. If the migration has not been attempted then this will be NULL.
  • status: a string indicating the status. It will be one of "Pending", "Successful", or "Failed".

◆ getAvailableMigrations()

static Drupal\tripal_chado\Task\ChadoApplyMigrations::getAvailableMigrations ( )
static

Gets details for all the current migrations available.

Returns
array An array of the migrations available where each element is an array with the keys filename, version, description.

◆ getHighestVersion()

static Drupal\tripal_chado\Task\ChadoApplyMigrations::getHighestVersion ( )
static

Gets the highest version number available in our migrations.

Returns
string The version of the latest migration. It will be a string of the form 1.3.3.005. If we are unable to get migrations or if there are not any migrations then the version returned will be the basline version (i.e. 1.3).

◆ getProgress()

Drupal\tripal_chado\Task\ChadoApplyMigrations::getProgress ( )

{Returns the percent of progress of current task.This method can also be used to check if a task is currently running if it has a > 0 value. A negative value means an error occured while running.

Returns
float A value between -1 and 1, 0 meaning the task has not been started yet, 1 meaning the task is completed with success and a negative value meaning that the task failed. The negative value may be used as a code to identify the error.
}

Implements Drupal\tripal_biodb\Task\BioTaskInterface.

◆ getStatus()

Drupal\tripal_chado\Task\ChadoApplyMigrations::getStatus ( )

{{Returns a string describing current status of the performed task.This function returns the last known status, even if the task ended. In case of failure, this function may return the reason of the failure.

Returns
string A localized description.
}}

Reimplemented from Drupal\tripal_biodb\Task\BioTaskBase.

◆ lookupInstallID()

Drupal\tripal_chado\Task\ChadoApplyMigrations::lookupInstallID ( )

Lookup the install ID based on the input schema name.

Returns
int|bool The install ID of the associated installation.

◆ performTask()

Drupal\tripal_chado\Task\ChadoApplyMigrations::performTask ( )

Applies all outstanding migrations to a given chado instance.

The migration procedure uses a set of SQL files where each migration is in it's own file.

Task parameter array provided to the class constructor includes:

  • 'input_schemas' array: one input schema that must exist (required)
  • 'output_schemas' array: no output schema as migrations are applied in place.

Example:

['input_schemas' => ['chado']]
Returns
bool TRUE if the task was performed with success and FALSE if the task was completed but without the expected success.
Exceptions
Drupal

tripal_biodb\Exception\TaskException Thrown when a major failure prevents the task from being performed.

Exceptions

Drupal\tripal_biodb\Exception\ParameterException Thrown if parameters are incorrect.

Exceptions
Drupal

tripal_biodb\Exception\LockException Thrown when the locks can't be acquired.

Reimplemented from Drupal\tripal_biodb\Task\BioTaskBase.

◆ reportMigrationStatus()

Drupal\tripal_chado\Task\ChadoApplyMigrations::reportMigrationStatus ( object  $migration,
bool  $status 
)

Saves the status of the current migration to the database.

Parameters
object$migration
  • version: a string of the form '1.3.3.002'.
  • install_id: the ID of the chado installation as managed by tripal.
  • schema_name: the name of the schema the status applies to.
  • description: a short description of the migration.
  • applied_on: the date the migration was applied on.
  • success: an integer indicating the success of applying the migration. If successful, it will be '1' and otherwise, '0'. If the migration has not been attempted then this will be NULL.
  • status: a string indicating the status. It will be one of "Pending", "Successful", or "Failed".
bool$status
Returns
void

◆ runTripalJob()

static Drupal\tripal_chado\Task\ChadoApplyMigrations::runTripalJob ( string  $schema_name,
int  $install_id,
TripalJob  $job 
)
static

A callable function to provide to tripal jobs as the callback.

Simply sets up the biotask with the details saved in the job and then performs the task.

Parameters
string$schema_nameThe schema to apply all pending migrations to.
int$install_idThe unique IF od the Tripal-managed chado installation the schema represents.

◆ setInstallID()

Drupal\tripal_chado\Task\ChadoApplyMigrations::setInstallID ( int  $install_id)

Sets the unique id of the Tripal-managed chado installation this biotask is focused on.

Parameters
int$install_id
Returns
void

◆ setTripalJob()

Drupal\tripal_chado\Task\ChadoApplyMigrations::setTripalJob ( TripalJob  $job)

Sets the Tripal job that the migrations are being applied during.

Parameters
TripalJob$job
Returns
void

◆ validateParameters()

Drupal\tripal_chado\Task\ChadoApplyMigrations::validateParameters ( )

Validate task parameters.

Parameter array provided to the class constructor must include one output schema:

['input_schemas' => ['chado']]
Exceptions

Drupal\tripal_biodb\Exception\ParameterException A descriptive exception is thrown in case of invalid parameters.

Implements Drupal\tripal_biodb\Task\BioTaskInterface.


The documentation for this class was generated from the following file: