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 changes the cv of local cvterms to the correct one
19 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
23 Naama Menda<nm249@cornell.edu>
25 =head1 COPYRIGHT & LICENSE
27 Copyright 2010 Boyce Thompson Institute for Plant Research
29 This program is free software; you can redistribute it and/or modify
30 it under the same terms as Perl itself.
35 package UpdateLocalCvterms
;
38 use Bio
::Chado
::Schema
;
41 extends
'CXGN::Metadata::Dbpatch';
44 has
'+description' => ( default => <<'' );
45 This patch will update the cv id of the following cvterms that currently have a
local cv name
48 breeding_program_trial_relationship
53 this is important
for making CVterms uniform
and having an explicit cv name that provides the right context
64 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
66 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
68 print STDOUT
"\nExecuting the SQL commands.\n";
69 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
72 my $cvterm_rs = $schema->resultset("Cv::Cvterm");
73 my $cv_rs = $schema->resultset("Cv::Cv");
75 my $nd_experiment_property_cv = $cv_rs->find_or_create( { name
=> 'nd_experiment_property' });
77 my $cross_type_cvterm = $cvterm_rs->search(
78 { name
=> 'cross_type', } );
80 if ( $cross_type_cvterm->count() == 0 ) {
81 print "Creating new cvterm 'cross_type' cv = 'nd_experiment_property' \n";
82 $cvterm_rs->create_with(
85 cv
=> 'nd_experiment_property',
88 print "Updating existing cvterm 'cross_type' cv = 'nd_experiment_property' \n";
89 $cross_type_cvterm->first->update( { cv_id
=> $nd_experiment_property_cv->cv_id }, );
92 my $number_of_flowers_cvterm = $cvterm_rs->search(
93 { name
=> 'number_of_flowers', } );
95 if ( $number_of_flowers_cvterm->count() == 0 ) {
96 print "Creating new cvterm 'number_of_flowers' cv = 'nd_experiment_property' \n";
97 $cvterm_rs->create_with(
99 name
=> 'number_of_flowers',
100 cv
=> 'nd_experiment_property',
103 print "Updating existing cvterm 'number_of_flowers' cv = 'nd_experiment_property' \n";
104 $number_of_flowers_cvterm->first->update( { cv_id
=> $nd_experiment_property_cv->cv_id }, );
107 my $number_of_seeds_cvterm = $cvterm_rs->search(
108 { name
=> 'number_of_seeds', } );
110 if ( $number_of_seeds_cvterm->count() == 0 ) {
111 print "Creating new cvterm 'number_of_seeds' cv = 'nd_experiment_property' \n";
112 $cvterm_rs->create_with(
114 name
=> 'number_of_seeds',
115 cv
=> 'nd_experiment_property',
118 print "Updating existing cvterm 'number_of_seeds' cv = 'nd_experiment_property' \n";
119 $number_of_seeds_cvterm->first->update( { cv_id
=> $nd_experiment_property_cv->cv_id }, );
124 my $project_property_cv = $cv_rs->find_or_create( { name
=> 'project_property' });
125 my $breeding_program_cvterm = $cvterm_rs->search(
126 { name
=> 'breeding_program', } );
128 if ( $breeding_program_cvterm->count() == 0 ) {
129 print "Creating new cvterm 'breeding_program' cv = 'project_property' \n";
130 $cvterm_rs->create_with(
132 name
=> 'breeding_program',
133 cv
=> 'project_property',
136 print "Updating existing cvterm 'breeding_program' cv = 'project_property' \n";
137 $breeding_program_cvterm->first->update( { cv_id
=> $project_property_cv->cv_id }, );
140 my $harvest_date_cvterm = $cvterm_rs->search(
141 { name
=> 'harvest_date', } );
143 if ( $harvest_date_cvterm->count() == 0 ) {
144 print "Creating new cvterm 'harvest_date' cv = 'project_property' \n";
145 $cvterm_rs->create_with(
147 name
=> 'harvest_date',
148 cv
=> 'project_property',
151 print "Updating existing cvterm 'harvest_date' cv = 'project_property' \n";
152 $harvest_date_cvterm->first->update( { cv_id
=> $project_property_cv->cv_id }, );
155 my $planting_date_cvterm = $cvterm_rs->search(
156 { name
=> 'planting_date', } );
158 if ( $planting_date_cvterm->count() == 0 ) {
159 print "Creating new cvterm 'planting_date' cv = 'project_property' \n";
160 $cvterm_rs->create_with(
162 name
=> 'planting_date',
163 cv
=> 'project_property',
166 print "Updating existing cvterm 'planting_date' cv = 'project_property' \n";
167 $planting_date_cvterm->first->update( { cv_id
=> $project_property_cv->cv_id }, );
171 my $project_relationship_cv = $cv_rs->find_or_create( { name
=> 'project_relationship' });
172 my $breeding_program_trial_cvterm = $cvterm_rs->search(
173 { name
=> 'breeding_program_trial_relationship', } );
175 if ( $breeding_program_trial_cvterm->count() == 0 ) {
176 print "Creating new cvterm 'breeding_program_trial_relationship' cv = 'project_relationship' \n";
177 $cvterm_rs->create_with(
179 name
=> 'breeding_program_trial_relationship',
180 cv
=> 'project_relationship',
183 print "Updating existing cvterm 'breeding_program_trial_relationship' cv = 'project_relationship' \n";
184 $breeding_program_trial_cvterm->first->update( { cv_id
=> $project_relationship_cv->cv_id }, );
190 print "Trial mode! Rolling back transaction\n\n";
191 $schema->txn_rollback;
198 $schema->txn_do($coderef);
201 die "Load failed! " . $_ . "\n" ;
205 print "You're done!\n";