function tripal_featuremap_update_7201
2.x tripal_featuremap.install | tripal_featuremap_update_7201() |
Adds missing foreign key constraints
File
- tripal_featuremap/
tripal_featuremap.install, line 537 - Handles installation of the feature map module
Code
function tripal_featuremap_update_7201() {
// Make sure we have the full API loaded this will help during a
// site upgrade when the tripal_core module is disabled.
module_load_include('module', 'tripal_core', 'tripal_core');
tripal_core_import_api();
// there was a bug in the function for creating a custom table that
// kept foreign key constraints from being added. So, we need to add those
// to keep from error messages appear, we will drop the FK if it already
// exists and then re-add it.
try {
$fkey_exists = db_query('SELECT TRUE FROM pg_constraint WHERE conname = :constraint', array(':constraint' => 'featuremapprop_type_id_fkey'))->fetchField();
if ($fkey_exists) {
// featuremapprop table
chado_query('
ALTER TABLE {featuremapprop}
DROP CONSTRAINT featuremapprop_type_id_fkey CASCADE
');
chado_query('
ALTER TABLE {featuremapprop}
DROP CONSTRAINT featuremapprop_featuremap_id_fkey CASCADE
');
}
chado_query('
ALTER TABLE {featuremapprop}
ADD CONSTRAINT featuremapprop_type_id_fkey
FOREIGN KEY (type_id) REFERENCES {cvterm} (cvterm_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
');
chado_query('
ALTER TABLE {featuremapprop}
ADD CONSTRAINT featuremapprop_featuremap_id_fkey
FOREIGN KEY (featuremap_id) REFERENCES {featuremap} (featuremap_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
');
// featuremap_dbref table
if ($fkey_exists) {
chado_query('
ALTER TABLE {featuremap_dbxref}
DROP CONSTRAINT featuremap_dbxref_dbxref_id_fkey CASCADE
');
chado_query('
ALTER TABLE {featuremap_dbxref}
DROP CONSTRAINT featuremap_dbxref_featuremap_id_fkey CASCADE
');
}
chado_query('
ALTER TABLE {featuremap_dbxref}
ADD CONSTRAINT featuremap_dbxref_dbxref_id_fkey
FOREIGN KEY (dbxref_id) REFERENCES {dbxref} (dbxref_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
');
chado_query('
ALTER TABLE {featuremap_dbxref}
ADD CONSTRAINT featuremap_dbxref_featuremap_id_fkey
FOREIGN KEY (featuremap_id) REFERENCES {featuremap} (featuremap_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
');
// featureposprop
if ($fkey_exists) {
chado_query('
ALTER TABLE {featureposprop}
DROP CONSTRAINT featureposprop_type_id_fkey CASCADE
');
chado_query('
ALTER TABLE {featureposprop}
DROP CONSTRAINT featureposprop_featurepos_id_fkey CASCADE
');
}
chado_query('
ALTER TABLE {featureposprop}
ADD CONSTRAINT featureposprop_type_id_fkey
FOREIGN KEY (type_id) REFERENCES {cvterm} (cvterm_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
');
chado_query('
ALTER TABLE {featureposprop}
ADD CONSTRAINT featureposprop_featurepos_id_fkey
FOREIGN KEY (featurepos_id) REFERENCES {featurepos} (featurepos_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
');
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to update foriegn key: ' . $error);
}
}