Merge pull request #2505 from solgenomics/topic/brapi_authentication
[sgn.git] / db / 00079 / AddGraftingCvterms.pm
blobe616b464af5b8526ed27399add8d10c3d4cc3bc4
1 #!/usr/bin/env perl
4 =head1 NAME
6 AddGraftingCvterms.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 AddGraftingCvterms;
38 use Moose;
39 use Bio::Chado::Schema;
40 use Try::Tiny;
41 extends 'CXGN::Metadata::Dbpatch';
44 has '+description' => ( default => <<'' );
45 Add missing cvterms for storing grafted stocks, and grafting experiments or projects
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 'stock_type' => [
69 'grafted_accession',
71 'stock_relationship' => [
72 'rootstock_of',
73 'scion_of',
75 'experiment_type' => [
76 'grafting_experiment',
78 'project_type' => [
79 'crossing_trial',
80 'grafting_trial',
81 'pollinating_trial'
85 foreach my $t (keys %$terms){
86 foreach (@{$terms->{$t}}){
87 $schema->resultset("Cv::Cvterm")->create_with({
88 name => $_,
89 cv => $t
90 });
95 print "You're done!\n";
99 ####
100 1; #
101 ####