Pass along stock type info to trials.mas to hide analysis usage table in non-accessio...
[sgn.git] / db / 00087 / UpdateProjectTypes.pm
blob7c9e17e581817e2295ca242bfbf3cffd52d6a095
1 #!/usr/bin/env perl
4 =head1 NAME
6 UpdateProjectTypes.pm
8 =head1 SYNOPSIS
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.
15 =head1 DESCRIPTION
16 This patch updates the cvterms phenotypeing_trial and genotyping_trial with cv = project_type to be consistent with other projectprops in the database
17 cvterm crossing_trial is redundant and is now deleted, as well as the cv.name trial_type. All trial types in the database should use the project_type cvterm since these are stored in the project table
20 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
22 =head1 AUTHOR
24 Naama Menda<nm249@cornell.edu>
26 =head1 COPYRIGHT & LICENSE
28 Copyright 2010 Boyce Thompson Institute for Plant Research
30 This program is free software; you can redistribute it and/or modify
31 it under the same terms as Perl itself.
33 =cut
36 package UpdateProjectTypes;
38 use Moose;
39 use Bio::Chado::Schema;
40 use SGN::Model::Cvterm;
41 use Try::Tiny;
42 extends 'CXGN::Metadata::Dbpatch';
46 has '+description' => ( default => <<'' );
47 This patch updates the cvterms phenotypeing_trial and genotyping_trial with cv = project_type to be consistent with other projectprops in the database
48 cvterm crossing_trial is redundant and is now deleted, as well as the cv.name trial_type. All trial types in the database should use the project_type cvterm since these are stored in the project table
50 has '+prereq' => (
51 default => sub {
52 ['AddGraftingCvterms', 'AddTrialTypes'],
57 sub patch {
58 my $self=shift;
60 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
62 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
64 print STDOUT "\nExecuting the SQL commands.\n";
65 my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );
69 my $phenotyping_cvterm = SGN::Model::Cvterm->get_cvterm_row($schema, 'phenotyping_trial', 'trial_type');
70 my $genotyping_cvterm = SGN::Model::Cvterm->get_cvterm_row($schema, 'genotyping_trial' , 'trial_type' ) ;
71 my $crossing_cvterm = SGN::Model::Cvterm->get_cvterm_row($schema, 'crossing_trial' , 'trial_type' ) ;
72 my $trial_type_cv = $schema->resultset("Cv::Cv")->find(
73 { name => 'trial_type' });
74 my $project_type_cv = $schema->resultset("Cv::Cv")->find(
75 { name => 'project_type' } );
77 $phenotyping_cvterm->update( { cv_id => $project_type_cv->cv_id } );
78 $genotyping_cvterm->update( { cv_id => $project_type_cv->cv_id } );
79 $crossing_cvterm->delete;
80 $trial_type_cv->delete;
82 print "You're done!\n";
86 ####
87 1; #
88 ####