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 deletes resundant project_property 'project harvest date' and 'project planting date' , adds 'project_' prefix to the existing cvterms, and updates the rows in teh projectprop table to point to the correct cvterm
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 UpdateProjectDateProps
;
38 use Bio
::Chado
::Schema
;
41 extends
'CXGN::Metadata::Dbpatch';
44 has
'+description' => ( default => <<'' );
45 This patch will update the cvterm name of
46 harvest_date
-> project_harvest_date
47 planting_date
-> project_planting_date
48 and remove the redundant terms
51 Rows
in projectprop that point to the redundant cvterms will be updated to point to the correct ones
62 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
64 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
66 print STDOUT
"\nExecuting the SQL commands.\n";
67 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
70 my $cvterm_rs = $schema->resultset("Cv::Cvterm");
71 my $cv_rs = $schema->resultset("Cv::Cv");
73 my $project_property_cv = $cv_rs->find( { name
=> 'project_property' });
75 my $harvest_date_cvterm = $cvterm_rs->search(
76 { name
=> 'harvest_date', } )->single;
78 print "Updating existing cvterm 'harvest_date' \n";
79 if ($harvest_date_cvterm) {
80 $harvest_date_cvterm->update( { name
=> 'project_harvest_date' }, );
82 $harvest_date_cvterm = $cvterm_rs->search( { name
=> 'project_harvest_date' } )->single;
84 my $harvest_date_cvterm_id = $harvest_date_cvterm->cvterm_id;
87 my $planting_date_cvterm = $cvterm_rs->search(
88 { name
=> 'planting_date', } )->single;
90 print "Updating existing cvterm 'planting_date' \n";
91 if ($planting_date_cvterm) {
92 $planting_date_cvterm->update( { name
=> 'project_planting_date'},);
94 $planting_date_cvterm = $cvterm_rs->search( { name
=> 'project_planting_date' } )->single;
96 my $planting_date_cvterm_id = $planting_date_cvterm->cvterm_id;
99 #redundant cvterms that should nopt be used
100 my $old_harvest_cvterm = $cvterm_rs->search(
101 { name
=> 'project harvest date', } )->single;
102 my $old_planting_cvterm = $cvterm_rs->search(
103 { name
=> 'project planting date' , })->single;
105 #update type_ids in projecprop table
106 if ($old_harvest_cvterm ) {
107 my $harvest_projectprops = $schema->resultset("Project::Projectprop")->search(
108 { type_id
=> $old_harvest_cvterm->cvterm_id , } );
109 $harvest_projectprops->update( { type_id
=> $harvest_date_cvterm_id , });
110 $old_harvest_cvterm->delete;
112 if ($old_planting_cvterm) {
113 my $planting_projectprops = $schema->resultset("Project::Projectprop")->search(
114 { type_id
=> $old_planting_cvterm->cvterm_id , } );
115 $planting_projectprops->update( { type_id
=> $planting_date_cvterm_id , });
117 #delete redundant cvterms
118 $old_planting_cvterm->delete;
123 print "Trial mode! Rolling back transaction\n\n";
124 $schema->txn_rollback;
131 $schema->txn_do($coderef);
134 die "Load failed! " . $_ . "\n" ;
138 print "You're done!\n";