Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / db / 00027 / AddBlastDbBlastDbGroupLinkingTable.pm
blob77c56130125cf1730ec824793598168f5bfffc68
1 #!/usr/bin/env perl
4 =head1 NAME
6 AddBlastDbBlastDbGroupLinkingTable.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
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
19 =head1 AUTHOR
21 Lukas Mueller<lam87@cornell.edu>
23 =head1 COPYRIGHT & LICENSE
25 Copyright 2010 Boyce Thompson Institute for Plant Research
27 This program is free software; you can redistribute it and/or modify
28 it under the same terms as Perl itself.
30 =cut
33 package AddBlastDbBlastDbGroupLinkingTable;
35 use Moose;
36 extends 'CXGN::Metadata::Dbpatch';
39 has '+description' => ( default => <<'' );
40 Adds a linking table between the blast_db and blast_db_group table
42 has '+prereq' => (
43 default => sub {
44 [ ],
48 sub patch {
49 my $self=shift;
51 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
53 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
55 print STDOUT "\nExecuting the SQL commands.\n";
57 $self->dbh->do(<<EOSQL);
58 --do your SQL here
61 create table blast_db_blast_db_group (
62 blast_db_blast_db_group_id serial primary key,
63 blast_db_id bigint REFERENCES blast_db,
64 blast_db_group_id bigint REFERENCES blast_db_group
67 -- populate table with current data from blast_db table
69 insert into sgn.blast_db_blast_db_group (blast_db_id, blast_db_group_id) SELECT blast_db_id, blast_db_group_id FROM sgn.blast_db;
71 -- also add blast_db_organism table
73 create table blast_db_organism (
74 blast_db_organism_id serial primary key,
75 blast_db_id bigint references sgn.blast_db,
76 organism_id bigint references public.organism
79 GRANT select ON sgn.blast_db_organism TO web_usr;
80 GRANT select ON sgn.blast_db_blast_db_group TO web_usr;
83 EOSQL
85 print "You're done!\n";
89 ####
90 1; #
91 ####