Merge pull request #5163 from solgenomics/audit-error-checking
[sgn.git] / db / 00081 / AddSeedlotListTypeCvterm.pm
blob1f771b5ce4e0d3516311761a0a7f21466acbd04d
1 #!/usr/bin/env perl
4 =head1 NAME
6 AddSeedlotListTypeCvterm.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 adds the necessary cvterms that are used for storing grafted stocks,
17 rootstock-scion stock_relationship, grafting_experiment ,and missing project types
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 AddSeedlotListTypeCvterm;
38 use Moose;
39 use Bio::Chado::Schema;
40 use Try::Tiny;
41 extends 'CXGN::Metadata::Dbpatch';
44 has '+description' => ( default => <<'' );
45 Add missing cvterm for seedlot list type
47 has '+prereq' => (
48 default => sub {
49 [],
54 sub patch {
55 my $self=shift;
57 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
59 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
61 print STDOUT "\nExecuting the SQL commands.\n";
62 my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );
65 print STDERR "INSERTING CVTERMS...\n";
67 my $terms = {
68 'list_types' => [
69 'seedlots',
73 foreach my $t (keys %$terms){
74 foreach (@{$terms->{$t}}){
75 $schema->resultset("Cv::Cvterm")->create_with({
76 name => $_,
77 cv => $t
78 });
83 print "You're done!\n";
87 ####
88 1; #
89 ####