for the t Mixed models
[sgn.git] / db / 00085 / UpdateNewProjectProps.pm
blobb7d2a64899752ea3bbf5e88e1a884ee7476faa64
1 #!/usr/bin/env perl
4 =head1 NAME
6 UpdateNewProjectProps
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
17 This patch updates cvterm name from
18 Genetic Gain to genetic_gain_trial,
19 Health Status to health_status_trial,
20 Heterosis to heterosis_trial
21 Storage to storage_trial
23 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
25 =head1 AUTHOR
27 Alex Ogbonna<aco46@cornell.edu>
29 =head1 COPYRIGHT & LICENSE
31 Copyright 2010 Boyce Thompson Institute for Plant Research
33 This program is free software; you can redistribute it and/or modify
34 it under the same terms as Perl itself.
36 =cut
39 package UpdateNewProjectProps;
41 use Moose;
42 use Bio::Chado::Schema;
43 use Try::Tiny;
45 extends 'CXGN::Metadata::Dbpatch';
48 has '+description' => ( default => <<'' );
49 This patch will update the cvterm name of
50 Genetic Gain -> genetic_gain_trial
51 Health Status -> health_status_trial
52 Heterosis -> heterosis_trial
53 Storage -> storage_trial
56 has '+prereq' => (
57 default => sub {
58 ['AddNewProjectType'],
62 sub patch {
63 my $self=shift;
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 } );
72 my $coderef = sub {
73 my $cvterm_rs = $schema->resultset("Cv::Cvterm");
74 my $cv_rs = $schema->resultset("Cv::Cv");
75 my $project_type_cv = $cv_rs->find( { name => 'project_type' });
77 my %cvterm_hash = (
78 'Genetic Gain' => 'genetic_gain_trial',
79 'Health Status' => 'health_status_trial',
80 'Heterosis' => 'heterosis_trial',
81 'Storage' => 'storage_trial',
84 foreach my $key (keys %cvterm_hash) {
85 my $cvterm = $cvterm_rs->search( { name => $key , cv_id => $project_type_cv->cv_id() });
86 if ( $cvterm != 0 ) {
87 print STDERR "Updating cvterm $key to " . $cvterm_hash{$key} . "\n";
88 my $cvterm_row = $cvterm->first();
89 $cvterm->update( { name => $cvterm_hash{$key} } ) ;
91 else { print "Cannot find cvterm $key in the database \n" ; }
94 if ($self->trial) {
95 print "Trial mode! Rolling back transaction\n\n";
96 $schema->txn_rollback;
97 return 0;
99 return 1;
102 try {
103 $schema->txn_do($coderef);
105 } catch {
106 die "Load failed! " . $_ . "\n" ;
110 print "You're done!\n";
113 ####
114 1; #
115 ####