1+ # !/usr/bin/env perl
2+
3+
4+ =head1 NAME
5+
6+ UpdateSeedlotsView
7+
8+ =head1 SYNOPSIS
9+
10+ mx-run UpdateSeedlotsView [options] -H hostname -D dbname -u username [-F]
11+
12+ this is a subclass of L<CXGN::Metadata::Dbpatch>
13+ see the perldoc of parent class for more details.
14+
15+ =head1 DESCRIPTION
16+
17+ This is a test dummy patch.
18+ This subclass uses L<Moose> . The parent class uses L<MooseX::Runnable>
19+
20+ =head1 AUTHOR
21+
22+ David Waring <djw64@cornell.edu>
23+
24+ =head1 COPYRIGHT & LICENSE
25+
26+ Copyright 2010 Boyce Thompson Institute for Plant Research
27+
28+ This program is free software; you can redistribute it and/or modify
29+ it under the same terms as Perl itself.
30+
31+ =cut
32+
33+
34+ package UpdateSeedlotsView ;
35+
36+ use Moose;
37+ extends ' CXGN::Metadata::Dbpatch' ;
38+
39+
40+ has ' +description' => ( default => <<'' );
41+ This updates the seedlots view to filter out discarded seedlots
42+
43+ has ' +prereq' => (
44+ default => sub {
45+ [],
46+ },
47+ );
48+
49+ sub patch {
50+ my $self =shift ;
51+
52+ print STDOUT " Executing the patch:\n " . $self -> name . " .\n\n Description:\n " . $self -> description . " .\n\n Executed by:\n " . $self -> username . " ." ;
53+
54+ print STDOUT " \n Checking if this db_patch was executed before or if previous db_patches have been executed.\n " ;
55+
56+ print STDOUT " \n Executing the SQL commands.\n " ;
57+
58+
59+ $self -> dbh()-> do( <<EOSQL );
60+ --do your SQL here
61+ --
62+ DROP VIEW IF EXISTS public.seedlots;
63+ CREATE VIEW public.seedlots AS
64+ SELECT stock.stock_id AS seedlot_id,
65+ stock.uniquename AS seedlot_name
66+ FROM stock
67+ WHERE stock.type_id = (SELECT cvterm_id from cvterm where cvterm.name = 'seedlot') AND is_obsolete = 'f'
68+ AND stock_id NOT IN (SELECT DISTINCT(stock_id) FROM stockprop WHERE type_id = (SELECT cvterm_id FROM cvterm WHERE name = 'discarded_metadata'))
69+ GROUP BY public.stock.stock_id, public.stock.uniquename;
70+ ALTER VIEW seedlots OWNER TO web_usr;
71+
72+ EOSQL
73+
74+ print " You're done!\n " ;
75+ }
76+
77+
78+ # ###
79+ 1; #
80+ # ###
0 commit comments