Changeset 4897
- Timestamp:
- Aug 29, 2005, 2:04:04 PM (21 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
Nebulous-Server/bin/neb-initdb (modified) (1 diff)
-
Nebulous/bin/neb-initdb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/bin/neb-initdb
r4882 r4897 1 1 #!/usr/bin/env perl 2 3 # Copyright (C) 2005 Joshua Hoblitt 4 # 5 # $Id: neb-initdb,v 1.2 2005-08-30 00:04:04 jhoblitt Exp $ 6 7 use strict; 8 use warnings FATAL => qw( all ); 9 10 use vars qw( $VERSION ); 11 $VERSION = '0.01'; 12 13 use DBI; 14 use Nebulous::Server::SQL; 15 16 use Getopt::Long qw( GetOptions :config auto_help auto_version ); 17 use Pod::Usage qw( pod2usage ); 18 19 my ($db, $dbuser, $dbpass); 20 GetOptions( 21 'db=s' => \$db, 22 'user=s' => \$dbuser, 23 'pass=s' => \$dbpass, 24 ) || pod2usage( 2 ); 25 26 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 27 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 ) 28 unless $db && $dbuser && $dbpass; 29 30 my $dbh = DBI->connect( 31 "DBI:mysql:database=$db:host=localhost", 32 $dbuser, 33 $dbpass, 34 { 35 RaiseError => 1, 36 PrintError => 0, 37 AutoCommit => 1, 38 }, 39 ); 40 41 my $sql = Nebulous::Server::SQL->new(); 42 43 print "Dropping any existing tables..."; 44 45 foreach my $statement (@{ $sql->get_db_clear }) { 46 $dbh->do( $statement ); 47 } 48 49 print " OK\nCreating new tables..."; 50 51 foreach my $statement (@{ $sql->get_db_schema }) { 52 $dbh->do( $statement ); 53 } 54 55 print " OK\n"; 56 57 __END__ 58 59 =pod 60 61 =head1 NAME 62 63 neb-initdb - initialize a Nebulous server database 64 65 =head1 SYNOPSIS 66 67 neb-initdb --db <database> --user <username> --pass <password> 68 69 =head1 DESCRIPTION 70 71 This program initialize a database for use by L<Nebulous::Server> by creating 72 the appropriate set of tables. Any pre-existing tables with conflicting names 73 are first removed. 74 75 =head1 OPTIONS 76 77 =over 4 78 79 =item * --db|-d <database> 80 81 Name of database (C<namespace>) to create tables in. 82 83 =item * --user|-u <username> 84 85 Username to authenticate with. 86 87 =item * --pass|-p <password> 88 89 Password to authenticate with. 90 91 =back 92 93 =head1 CREDITS 94 95 Just me, myself, and I. 96 97 =head1 SUPPORT 98 99 Please contact the author directly via e-mail. 100 101 =head1 AUTHOR 102 103 Joshua Hoblitt <jhoblitt@cpan.org> 104 105 =head1 COPYRIGHT 106 107 Copyright (C) 2005 Joshua Hoblitt. All rights reserved. 108 109 This program is free software; you can redistribute it and/or modify it under 110 the terms of the GNU General Public License as published by the Free Software 111 Foundation; either version 2 of the License, or (at your option) any later 112 version. 113 114 This program is distributed in the hope that it will be useful, but WITHOUT ANY 115 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 116 PARTICULAR PURPOSE. See the GNU General Public License for more details. 117 118 You should have received a copy of the GNU General Public License along with 119 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 120 Place - Suite 330, Boston, MA 02111-1307, USA. 121 122 The full text of the license can be found in the L<perlgpl> Pod as supplied 123 with Perl 5.8.1 and later. 124 125 =head1 SEE ALSO 126 127 L<Nebulous::Server> 128 129 =cut -
trunk/Nebulous/bin/neb-initdb
r4882 r4897 1 1 #!/usr/bin/env perl 2 3 # Copyright (C) 2005 Joshua Hoblitt 4 # 5 # $Id: neb-initdb,v 1.2 2005-08-30 00:04:04 jhoblitt Exp $ 6 7 use strict; 8 use warnings FATAL => qw( all ); 9 10 use vars qw( $VERSION ); 11 $VERSION = '0.01'; 12 13 use DBI; 14 use Nebulous::Server::SQL; 15 16 use Getopt::Long qw( GetOptions :config auto_help auto_version ); 17 use Pod::Usage qw( pod2usage ); 18 19 my ($db, $dbuser, $dbpass); 20 GetOptions( 21 'db=s' => \$db, 22 'user=s' => \$dbuser, 23 'pass=s' => \$dbpass, 24 ) || pod2usage( 2 ); 25 26 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 27 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 ) 28 unless $db && $dbuser && $dbpass; 29 30 my $dbh = DBI->connect( 31 "DBI:mysql:database=$db:host=localhost", 32 $dbuser, 33 $dbpass, 34 { 35 RaiseError => 1, 36 PrintError => 0, 37 AutoCommit => 1, 38 }, 39 ); 40 41 my $sql = Nebulous::Server::SQL->new(); 42 43 print "Dropping any existing tables..."; 44 45 foreach my $statement (@{ $sql->get_db_clear }) { 46 $dbh->do( $statement ); 47 } 48 49 print " OK\nCreating new tables..."; 50 51 foreach my $statement (@{ $sql->get_db_schema }) { 52 $dbh->do( $statement ); 53 } 54 55 print " OK\n"; 56 57 __END__ 58 59 =pod 60 61 =head1 NAME 62 63 neb-initdb - initialize a Nebulous server database 64 65 =head1 SYNOPSIS 66 67 neb-initdb --db <database> --user <username> --pass <password> 68 69 =head1 DESCRIPTION 70 71 This program initialize a database for use by L<Nebulous::Server> by creating 72 the appropriate set of tables. Any pre-existing tables with conflicting names 73 are first removed. 74 75 =head1 OPTIONS 76 77 =over 4 78 79 =item * --db|-d <database> 80 81 Name of database (C<namespace>) to create tables in. 82 83 =item * --user|-u <username> 84 85 Username to authenticate with. 86 87 =item * --pass|-p <password> 88 89 Password to authenticate with. 90 91 =back 92 93 =head1 CREDITS 94 95 Just me, myself, and I. 96 97 =head1 SUPPORT 98 99 Please contact the author directly via e-mail. 100 101 =head1 AUTHOR 102 103 Joshua Hoblitt <jhoblitt@cpan.org> 104 105 =head1 COPYRIGHT 106 107 Copyright (C) 2005 Joshua Hoblitt. All rights reserved. 108 109 This program is free software; you can redistribute it and/or modify it under 110 the terms of the GNU General Public License as published by the Free Software 111 Foundation; either version 2 of the License, or (at your option) any later 112 version. 113 114 This program is distributed in the hope that it will be useful, but WITHOUT ANY 115 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 116 PARTICULAR PURPOSE. See the GNU General Public License for more details. 117 118 You should have received a copy of the GNU General Public License along with 119 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 120 Place - Suite 330, Boston, MA 02111-1307, USA. 121 122 The full text of the license can be found in the L<perlgpl> Pod as supplied 123 with Perl 5.8.1 and later. 124 125 =head1 SEE ALSO 126 127 L<Nebulous::Server> 128 129 =cut
Note:
See TracChangeset
for help on using the changeset viewer.
