Upgrade a given chado schema to the specified version.
Before using this function, we recommand you backup your database and/or clone your Chado schema first and try to upgrade that clone first. In case of failure during the upgrade process, the upgraded schema may become unusable so you will have to restore a working version. But be careful, even if the upgrade process scceeded, it may have removed some data that did not feet in the reference schema. Therefore, you will have to check the content of the upgraded schema and may have to manully import back removed data (it could be custom tables, columns, functions, whatever that was not present in the official Chado schema version selected).
The upgrade process
First, if no reference input schema is provieded, we create a new Chado template schema (see CHADO_REF_SCHEMA*) to use as a reference for the upgrade process. The structure of the reference schema will be "applied" to the schema to upgrade. In the end, the schema to upgrade will contain the same functions, tables, columns, views, etc. that the reference schema has.
After the reference schema is setup (or selected), we process each PostgreSQL object categories and compare the schema to upgrade to the reference one. When changes are required, we store the corresponding SQL queries for each object in the 'upgradeQueries' class member. Cleanup queries are stored in 'upgradeQueries['#cleanup']' in order to remove unnecessary objects.
The upgrade process is the following: 1) Prepare table column defaults removal in table definitions (ie. remove sequences and function dependencies) 2) Prepare functions and aggregate functions removal 3) Prepare views removal 4) Prepare database type upgrade 5) Prepare sequence upgrade 6) Prepare function prototypes (for function inter-dependencies) 7) Prepare table column type upgrade Columns that match $chado_column_upgrade will be upgraded using the corresponding queries. Other columns will be updated using default behavior. Defaults are dropped and will be added later. 8) Prepare sequence association (to table columns) 9) Prepare view upgrade 10) Prepare function upgrade 11) Prepare aggregate function upgrade 12) Prepare table column default upgrade 13) Prepare comment upgrade 14) Prepare data initialization 15) Process upgrade queries 16) Update Tripal integration
Note: a couple of PostgreSQL object are not processed as they are not part of Chado schema specifications: collations, domains, triggers, unlogged tables and materialized views (in PostgreSQL sens, Tripal MV could be processed but are removed by default and will need to be recreated).
Parameters
Task parameter array provided to the class constructor includes:
- 'output_schemas' array: one output Chado schema that must exist and contain data (required). This ouput schema is the schema that needs to be upgraded.
- 'input_schemas' array: no input schema or a reference schema name (for advanced users). See above documentation to understand what the refrence schema stand for. If the reference schema is not provided, the default one will be used. If the reference schema does not exist, it will be created. If it exists, it will be used as is and any provided version number will be ignored.
- 'version' string: a version number (optional, default to ::DEFAULT_CHADO_VERSION)
- 'cleanup' bool: a cleanup flag that tells if existing database objects no present in the reference schema should be removed (cleanup = TRUE) or not (cleanup = FALSE). Warning: if set to TRUE, uncleaned elements may prevent some parts of the schema to be upgraded and therefore, the upgrade process has more chances to fail. If you have data that are not part of the official Chado schema but you want to keep, you may try to set this flag to FALSE to try to keep them and avoid having to put them back manully in a cleaned upgraded version. Default to TRUE (ie. things will be cleaned up).
- 'filename' string: when a path to an unexisting file name is provided, NO upgrade will be performed. Instead, every SQL query part of the upgrade will be written into that file. This SQL file can be later used to upgrade the schema manually. However, please note that a reference schema will be created if needed and the queries have been designed to work using the provided schema names. Any change on schema names of the schema to upgrade or the reference schema will lead to issues when the SQL queries will be run. The file path can be absolute (starting with a '/') or relative to the site 'files' directory (or private directory if it the the default). Default: no file path.
Example:
[
'output_schemas' => ['chado'],
'version' => '1.3',
'cleanup' => TRUE,
'filename' => 'upgrade_queries.sql',
]
- Returns
- bool TRUE if the task was performed with success and FALSE if the task was completed but without the expected success.
- Exceptions
-
Reimplemented from Drupal\tripal_biodb\Task\BioTaskBase.