« blib/lib/auto/share/dist/MOBY/scripts/CloneCentralDatabases.pl
↑ Summary
blib/lib/MOBY/Client/Registration.pm »
| 1 | #!/usr/local/bin/perl -w | ||
| 2 | # | ||
| 3 | # script to update the db | ||
| 4 | # | ||
| 5 | # $Id: moby-s-update-db.pl,v 1.2 2009/04/03 16:50:50 kawas Exp $ | ||
| 6 | # Contact: Edward Kawas <edward.kawas@gmail.com> | ||
| 7 | # ----------------------------------------------------------- | ||
| 8 | use strict; | ||
| 9 | use DBI; | ||
| 10 | use DBD::mysql; | ||
| 11 | |||
| 12 | BEGIN { | ||
| 13 | use Getopt::Std; | ||
| 14 | use vars qw/ $opt_h $opt_c /; | ||
| 15 | getopts('hc'); | ||
| 16 | |||
| 17 | use constant MSWIN => $^O =~ /MSWin32|Windows_NT/i ? 1 : 0; | ||
| 18 | |||
| 19 | # usage | ||
| 20 | if ($opt_h or not $opt_c) { | ||
| 21 | print STDOUT <<'END_OF_USAGE'; | ||
| 22 | Script to help update your BioMOBY registry database. | ||
| 23 | |||
| 24 | Usage: moby-s-update-db.pl [-h] -c | ||
| 25 | |||
| 26 | -c ..... update the db to include cgi-async | ||
| 27 | as a service category. | ||
| 28 | |||
| 29 | -h ..... shows this message | ||
| 30 | |||
| 31 | You will need to know the username/password of a user | ||
| 32 | with write access to the BioMOBY databases. | ||
| 33 | |||
| 34 | Good luck! | ||
| 35 | |||
| 36 | |||
| 37 | END_OF_USAGE | ||
| 38 | exit(0); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | if ($opt_c) { | ||
| 43 | |||
| 44 | print "\n\n\n | ||
| 45 | \tThis script will update your mobycentral database such that | ||
| 46 | \tthe service_instance table has a category enum field of 'cgi-async'. | ||
| 47 | |||
| 48 | |||
| 49 | \tThe login you use below MUST have administration privileges | ||
| 50 | \ton the mobycentral database! | ||
| 51 | \n\n"; | ||
| 52 | |||
| 53 | my $go = 1; # change this to '0' for a dry run... | ||
| 54 | |||
| 55 | print "Central Registry Databasename [mobycentral]: "; | ||
| 56 | my $dbname = <STDIN>; | ||
| 57 | chomp $dbname; | ||
| 58 | $dbname ||= 'mobycentral'; | ||
| 59 | print "\n"; | ||
| 60 | |||
| 61 | print "Central Registry Database URL [localhost]: "; | ||
| 62 | my $url = <STDIN>; | ||
| 63 | chomp $url; | ||
| 64 | $url ||= 'localhost'; | ||
| 65 | print "\n"; | ||
| 66 | |||
| 67 | print "Central Registry Database Port [3306]: "; | ||
| 68 | my $port = <STDIN>; | ||
| 69 | chomp $port; | ||
| 70 | $port ||= 3306; | ||
| 71 | print "\n"; | ||
| 72 | |||
| 73 | print "Central Registry Database Username [root]: "; | ||
| 74 | my $username = <STDIN>; | ||
| 75 | chomp $username; | ||
| 76 | $username ||= 'root'; | ||
| 77 | print "\n"; | ||
| 78 | |||
| 79 | print "Cenral Registry Database Password [undef]: "; | ||
| 80 | my $password = <STDIN>; | ||
| 81 | chomp $password; | ||
| 82 | $password ||= undef; | ||
| 83 | print "\n"; | ||
| 84 | |||
| 85 | my $driver = 'DBI:mysql'; | ||
| 86 | my ($dsn) = "$driver:$dbname:$url:$port"; | ||
| 87 | my $dbh = DBI->connect( $dsn, $username, $password, { RaiseError => 1 } ) | ||
| 88 | or die "can't connect to database"; | ||
| 89 | die "can't connect to database\n" unless $dbh; | ||
| 90 | |||
| 91 | # does the field already exist? | ||
| 92 | my $results = $dbh->selectall_hashref( 'describe service_instance', 'Field' ); | ||
| 93 | |||
| 94 | my $category = $results->{category}->{Type} | ||
| 95 | if defined $results->{category} and $results->{category}->{Type}; | ||
| 96 | |||
| 97 | die "Database doesn't seem to be created yet." unless $category; | ||
| 98 | |||
| 99 | unless ( $category =~ m/cgi\-async/i ) { | ||
| 100 | $go | ||
| 101 | && $dbh->do( | ||
| 102 | " alter table service_instance modify category ENUM('moby','soap','wsdl','cgi','moby-async', 'cgi-async', 'doc-literal', 'doc-literal-async') default NULL" | ||
| 103 | ); | ||
| 104 | } | ||
| 105 | |||
| 106 | print "\nUpdate Complete!\n"; | ||
| 107 | } |