Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / db / 00073 / AddComposedTraitCv.pm
blobcdef93276cd67c75c748c3fb11d4376a4eb13040
1 #!/usr/bin/env perl
4 =head1 NAME
6 AddComposedTraitCv
8 =head1 SYNOPSIS
10 mx-run AddComposedTraitCv [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 Adds a composed trait cv with namespace COMP to allow composition of traits
18 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
20 =head1 AUTHOR
22 Bryan Ellerbrock<bje24@cornell.edu>
24 =head1 COPYRIGHT & LICENSE
26 Copyright 2011 Boyce Thompson Institute for Plant Research
28 This program is free software; you can redistribute it and/or modify
29 it under the same terms as Perl itself.
31 =cut
34 package AddComposedTraitCv;
36 use Moose;
37 extends 'CXGN::Metadata::Dbpatch';
40 has '+description' => ( default => <<'' );
41 Adds a composed trait cv with namespace COMP to allow composition of traits
44 sub patch {
45 my $self=shift;
47 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
49 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
51 print STDOUT "\nExecuting the SQL commands.\n";
53 $self->dbh->do(<<EOSQL);
54 --do your SQL here
57 -- add cv and db for composed traits
59 INSERT into db (name) values ('COMP');
60 CREATE SEQUENCE composed_trait_ids;
61 ALTER SEQUENCE composed_trait_ids OWNER TO web_usr;
62 GRANT ALL ON cvterm_relationship to web_usr;
63 GRANT ALL ON cvterm_relationship_cvterm_relationship_id_seq to web_usr;
64 GRANT ALL ON cvtermsynonym to web_usr;
65 GRANT ALL ON cvtermsynonym_cvtermsynonym_id_seq to web_usr;
66 INSERT into cv (name) values ('composed_trait');
67 INSERT into dbxref (db_id, accession) select db_id, nextval('composed_trait_ids') from db where name = 'COMP';
68 INSERT into cvterm (cv_id,name,dbxref_id) select cv_id, 'Composed traits', dbxref_id from cv join db on true AND db.name = 'COMP' join dbxref using(db_id) where cv.name = 'composed_trait';
70 EOSQL
72 print "You're done!\n";
76 ####
77 1; #
78 ####