10 mx-run ThisPackageName [options] -H hostname -D dbname -u username [-F]
12 this is a subclass of L<CXGN::Metadata::Dbpatch>
13 see the perldoc of parent class for more details.
17 This patch cleans up system cvterms terms that are
20 3. are used in the wrong context (e.g. stock_relationship cvterm used in the nd_experimentprop table)
22 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
26 Naama Menda<nm249@cornell.edu>
28 =head1 COPYRIGHT & LICENSE
30 Copyright 2010 Boyce Thompson Institute for Plant Research
32 This program is free software; you can redistribute it and/or modify
33 it under the same terms as Perl itself.
38 package FixRedundantCvterms
;
41 use Bio
::Chado
::Schema
;
44 extends
'CXGN::Metadata::Dbpatch';
47 has
'+description' => ( default => <<'' );
48 This patch will
do the following
:
49 1. Set cv_id
= nd_experiment_property
for the cvterm cross_name
50 2. Update the type_id of nd_experiment rows to cross_experiment where the type_id
= cross
, and then obsolete this stock_relationship cross cvterm
51 3. Create a new term called cross_relationship cv
= stock_relationship to be used
52 in the stock_relationship table instead of the term cross_name which now
53 has a nd_experiment_property cv
and is used as type_id
in nd_experimentprop
54 this is important
for making CVterms uniform
and less room
for errors
when using these
65 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
67 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
69 print STDOUT
"\nExecuting the SQL commands.\n";
70 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
73 my $cvterm_rs = $schema->resultset("Cv::Cvterm");
74 my $cv_rs = $schema->resultset("Cv::Cv");
79 my $nd_experiment_property_cv = $cv_rs->find_or_create( { name
=> 'nd_experiment_property' } ) ;
81 my $cross_name_cvterm = $cvterm_rs->find(
83 name
=> 'cross_name' ,
85 if ($cross_name_cvterm) {
86 print "UPDATING cv_id of cvterm cross_name to nd_experiment_property\n";
87 $cross_name_cvterm->update( { cv_id
=> $nd_experiment_property_cv->cv_id } ) ;
91 my $cross_experiment_cvterm = $cvterm_rs->create_with(
93 name
=> 'cross_experiment',
94 cv
=> 'experiment_type',
97 my $nd_experiment_rs = $schema->resultset("NaturalDiversity::NdExperiment")->search(
99 'type.name' => 'cross'
104 if ( $nd_experiment_rs->count ) {
105 print "UPDATING nd_experiment with type_id = cross to type_id = cross_experiment\n";
106 $nd_experiment_rs->update( { type_id
=> $cross_experiment_cvterm->cvterm_id } );
108 ### OBSOLETE name of cross cvterm cv = stock_relationship
109 my $cross_cvterm = $cvterm_rs->find(
111 'me.name' => 'cross',
112 'cv.name' => 'stock_relationship',
117 if ( $cross_cvterm ) {
118 print "UPDATING term cross cv= stock_relationship to name = OBSOLETE_cross. No one should use this term. There is a cross term with stock_type cv\n";
119 $cross_cvterm->update( { name
=> 'OBSOLETE_cross' } ) ;
123 my $cross_relationship_cvterm = $cvterm_rs->create_with(
125 name
=> 'cross_relationship' ,
126 cv
=> 'stock_relationship',
129 my $stock_relationship_rs = $schema->resultset("Stock::StockRelationship")->search(
131 'type.name' => 'cross_name',
135 if ( $stock_relationship_rs->count ) {
136 print "UPDATING stock_relationships with type = cross_name to new cvterm = cross_relationship. You should not use the term cross in stock_relationship. It should be only a stock.type \n";
137 $stock_relationship_rs->update( { type_id
=> $cross_relationship_cvterm->cvterm_id } );
142 print "Trial mode! Rolling back transaction\n\n";
143 $schema->txn_rollback;
151 $schema->txn_do($coderef);
154 die "Load failed! " . $_ . "\n" ;
158 print "You're done!\n";