#!/usr/bin/perl -w -I/opt/eprints/perl_lib

######################################################################
#
#  This file is part of EPrints 2.
#  
#  EPrints 2 is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  EPrints 2 is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with EPrints 2; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
######################################################################

=pod

=head1 NAME

B<create_tables> - create SQL tables for an EPrints archive

=head1 SYNOPSIS

B<create_tables> I<archiveid> [B<options>]

=head1 DESCRIPTION

Create the SQL tables which the EPrints software will use. 

You should run B<import_subjects> after this, actually it will remind you unless you make it B<--quiet>.

=head1 ARGUMENTS

=over 8

=item I<archiveid> 

The ID of the EPrint archive to effect.

=back

=head1 OPTIONS

=over 8

=item B<--help>

Print a brief help message and exit.

=item B<--man>

Print the full manual page and then exit.

=item B<--quiet>

Be vewwy vewwy quiet. This option will supress all output unless an error occurs.

=item B<--verbose>

Explain in detail what is going on.

=back   

=head1 AUTHOR

This is part of this EPrints-2 system. EPrints-2 is written by Christopher Gutteridge. EPrints-1 was written by Robert Tansley.

=head1 VERSION

EPrints Version: 2.0

=head1 CONTACT

For more information goto B<http://www.eprints.org/> which give information on mailing lists and the like.

Chris Gutteridge may be contacted at B<support@eprints.org>

Should you need a real world address for some reason, EPrints can be contacted in the real world at

 EPrints c/o Christopher Gutteridge
 Department of Electronics and Computer Science
 University of Southampton
 SO17 1BJ
 United Kingdom

=head1 LICENSE

This file is part of EPrints 2.

EPrints 2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

EPrints 2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with EPrints 2; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

=cut



use EPrints::Database;
use EPrints::Session;
use EPrints::Subject;

use strict;
use Getopt::Long;
use Pod::Usage;

my $verbose = 0;
my $quiet = 0;
my $help = 0;
my $man = 0;

GetOptions( 
	'help|?' => => \$help,
	'man' => => \$man,
	'verbose+' => \$verbose,
	'quiet' => \$quiet
) || pod2usage( 2 );
pod2usage( 1 ) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
pod2usage( 2 ) if( scalar @ARGV != 1 ); 

my $noise = 1;
$noise = 0 if( $quiet );
$noise = 1+$verbose if( $verbose );

# Set STDOUT to auto flush (without needing a \n)
$|=1;

my $session = new EPrints::Session( 1, $ARGV[0], $noise, 1 );
exit( 1 ) unless defined $session;

if( $noise>=1 ) { print "Creating database tables...\n"; }
if( $session->get_db()->create_archive_tables() )
{
	if( $noise>=1 ) { print "...done creating database tables.\n"; }
}
else
{
	my $error = $session->get_db()->error();
	print STDERR "DB Error: $error\n";
}

if( $noise>=1 ) { print "You should really run import_subjects now.\n"; }

$session->terminate();
exit;


