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.
17 This is a patch for populating the stockpub table , and granting web_usr permissions
19 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
23 Naama Menda<nm249@cornell.edu>
25 =head1 COPYRIGHT & LICENSE
27 Copyright 2010 Boyce Thompson Institute for Plant Research
29 This program is free software; you can redistribute it and/or modify
30 it under the same terms as Perl itself.
35 package PopulateStockPub
;
38 extends
'CXGN::Metadata::Dbpatch';
40 use Bio
::Chado
::Schema
;
44 my $name = __PACKAGE__
;
45 print "dbpatch name is ':" . $name . "\n\n";
46 my $description = 'Populating stock_pub table';
47 my @previous_requested_patches = (); #ADD HERE
49 $self->description($description);
50 $self->prereq(\
@previous_requested_patches);
56 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
58 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
60 print STDOUT
"\nExecuting the SQL commands.\n";
61 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
63 my $stockdbxrefs = $schema->resultset("General::Db")->search( { name
=> 'PMID' } )
64 ->search_related('dbxrefs')->search_related('stock_dbxrefs');
65 my $result = $schema->txn_do( sub {
66 while ( my $sd = $stockdbxrefs->next ) {
67 $sd->stock->find_or_create_related('stock_pubs' , {
68 pub_id
=> $sd->dbxref->search_related('pub_dbxrefs')->search_related('pub')->first->pub_id
70 print "Added publication for stock " . $sd->stock->name . "\n";
73 print "Trial mode! Rolling back transaction.\n\n";
74 $schema->txn_rollback;
77 print "Committing.\n";
83 $self->dbh->do(<<EOSQL);
86 --grant permissions to web_usr
87 grant ALL on public.stock_pub to web_usr ;
88 grant USAGE on public.stock_pub_stock_pub_id_seq TO web_usr ;
92 print $result ?
"Patch applied successfully.\n" : "Patch not applied.\n";