Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / db / 00179 / AddFilesStockLinkingTable.pm
blob03929728271c9c318be9921fa75facf96dc14f20
1 #!/usr/bin/env perl
4 =head1 NAME
6 AddFilesStockLinkingTable.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 Mirella Flores <mrf252@cornell.edu>
23 =head1 COPYRIGHT & LICENSE
25 Copyright 2023 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 AddFilesStockLinkingTable;
35 use Moose;
36 extends 'CXGN::Metadata::Dbpatch';
39 has '+description' => ( default => <<'' );
40 Adds the linking table between files and stock to Phenome
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 phenome.stock_file (
62 stock_file_id serial primary key,
63 stock_id int4 NOT NULL REFERENCES stock ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
64 file_id int4 NOT NULL REFERENCES metadata.md_files ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
67 GRANT UPDATE, INSERT, SELECT ON phenome.stock_file TO web_usr;
68 GRANT USAGE ON phenome.stock_file_stock_file_id_seq to web_usr;
70 EOSQL
72 print "You're done!\n";
76 ####
77 1; #
78 ####