10 mx-run FixTrialPluralTypes [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.
16 This patch fixes the odd "Preliminary Yield Trials" and "Advanced Yeld Trials" and "Advanced Yield Trials" terms that should be singular terms
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
22 =head1 COPYRIGHT & LICENSE
24 Copyright 2010 Boyce Thompson Institute for Plant Research
26 This program is free software; you can redistribute it and/or modify
27 it under the same terms as Perl itself.
32 package FixTrialPluralTypes
;
35 use Bio
::Chado
::Schema
;
37 use SGN
::Model
::Cvterm
;
38 extends
'CXGN::Metadata::Dbpatch';
41 has
'+description' => ( default => <<'' );
42 This patch fixes the odd
"Preliminary Yield Trials" and "Advanced Yeld Trials" and "Advanced Yield Trials" terms that should be singular terms
54 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
56 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
58 print STDOUT
"\nExecuting the SQL commands.\n";
59 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
62 print STDERR
"INSERTING CV TERMS...\n";
64 my $correct_ayt_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'Advanced Yield Trial', 'project_type')->cvterm_id();
65 my $correct_pyt_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'Preliminary Yield Trial', 'project_type')->cvterm_id();
67 my $previously_saved_wrong_ayt_projectprops_sql = "SELECT projectprop_id FROM projectprop join cvterm on(type_id=cvterm_id) where name='Advanced Yeld Trials' OR name='Advanced Yield Trials';";
68 my $update_previously_saved_wrong_ayt_projectprops_sql = "UPDATE projectprop SET type_id = $correct_ayt_cvterm_id WHERE projectprop_id = ?;";
70 my $h1 = $schema->storage->dbh()->prepare($previously_saved_wrong_ayt_projectprops_sql);
71 my $h_update = $schema->storage->dbh()->prepare($update_previously_saved_wrong_ayt_projectprops_sql);
74 while (my ($projectprop_id) = $h1->fetchrow_array()) {
75 $h_update->execute($projectprop_id);
78 my $previously_saved_wrong_pyt_projectprops_sql = "SELECT projectprop_id FROM projectprop join cvterm on(type_id=cvterm_id) where name='Preliminary Yield Trials';";
79 my $update_previously_saved_wrong_pyt_projectprops_sql = "UPDATE projectprop SET type_id = $correct_pyt_cvterm_id WHERE projectprop_id = ?;";
81 my $h2 = $schema->storage->dbh()->prepare($previously_saved_wrong_pyt_projectprops_sql);
82 my $h2_update = $schema->storage->dbh()->prepare($update_previously_saved_wrong_pyt_projectprops_sql);
85 while (my ($projectprop_id) = $h2->fetchrow_array()) {
86 $h2_update->execute($projectprop_id);
89 my $wrong_trial_types_rs = $schema->resultset("Cv::Cvterm")->search({
90 name
=> {-in => ["Advanced Yeld Trials", "Advanced Yield Trials", "Preliminary Yield Trials"]}
92 while (my $r = $wrong_trial_types_rs->next){
96 print "You're done!\n";