Merge branch 'topic/add_brapi_logo' into topic/brapi_logo
[sgn.git] / bin / refresh_materialized_markerview.pl
blobae8f48f36b1cf7b2a468d5721cb285bd73c4cf81
1 #!/usr/bin/perl
3 =head1 NAME
5 refresh_materialized_markerview.pl - run the create_materialized_markerview postgres function that rebuilds the unified marker materialized view
7 =head1 DESCRIPTION
9 refresh_materialized_markerview.pl -H [database host] -D [database name] -U [database username] -P [database password]
11 Options:
13 -H the database host
14 -D the database name
15 -U the database username
16 -P the database password
18 This script will rebuild the materialized_markerview table and refresh its contents
20 =head1 AUTHOR
22 Bryan Ellerbrock <bje24@cornell.edu>
23 David Waring <djw64@cornell.edu> - modified from refresh_matviews.pl script
25 =cut
27 use strict;
28 use warnings;
29 use Getopt::Std;
30 use DBI;
32 our ($opt_H, $opt_D, $opt_U, $opt_P);
33 getopts('H:D:U:P:');
35 print STDERR "Connecting to database...\n";
36 my $dsn = 'dbi:Pg:database='.$opt_D.";host=".$opt_H.";port=5432";
37 my $dbh = DBI->connect($dsn, $opt_U, $opt_P);
39 eval {
40 print STDERR "Refreshing materialized_markerview . . . " . localtime() . "\n";
42 my $q = "SELECT public.create_materialized_markerview(true);";
43 my $h = $dbh->prepare($q);
44 $h->execute();
46 print STDERR "materialized_markerview refreshed! " . localtime() . "\n";
49 if ($@) {
50 $dbh->rollback();
51 print STDERR $@;
52 } else {
53 print STDERR "Done, exiting refresh_matviews.pl \n";