GBrowse

 view release on metacpan or  search on metacpan

bin/gbrowse_metadb_config.pl  view on Meta::CPAN

use File::Spec;
use POSIX 'strftime';

use constant SCHEMA_VERSION => 4;

# First, collect all the flags - or output the correct usage, if none listed.
my @argv = @ARGV;

my ($dsn, $admin);
GetOptions('dsn=s'         => \$dsn,
           'admin=s'       => \$admin) or die <<EOF;
Usage: $0 [options] <optional path to GBrowse.conf>

Initializes an empty GBrowse user accounts and uploads metadata database.
Options:

   -dsn       Provide a custom DBI connection string, overriding what is
              set in Gbrowse.conf. Note that if there are semicolons in the
              string (like most MySQL connection DSNs will), you WILL have
              to escape it with quotes.
   -admin     Provide an administrator username and password (in the form
              'user:pass') to skip the prompts if the database does not
              exist.

Currently mysql and SQLite databases are supported. When creating a
mysql database you must provide the -admin option to specify a user
and password that has database create privileges on the server.
EOF
    ;

my $www_user       = GBrowse::ConfigData->config('wwwuser');
my ($current_user) = getpwuid($<);

unless ($www_user eq $current_user or $< == 0) {
    print STDERR <<END;
For user account installation to work properly, this script must be able to
create directories owned by the Apache server account ($www_user).
This script will now invoke sudo to become the 'root' user temporarily.
You may be prompted for your login password now.
END
;
    exec 'sudo','-u','root',$0,@argv;
}

my $line_counter  = 0; # controls newlines

# Open the connections.
my $globals = Bio::Graphics::Browser2->open_globals;
$dsn ||= $globals->user_account_db;
if (!$dsn || ($dsn =~ /filesystem|memory/i) || !$globals->user_accounts) {
    print "No need to run database metadata configuration script, filesystem-backend will be used.";
    exit 0;
}

fix_sqlite_permissions()     if $dsn =~ /sqlite/i;
create_mysql_database()      if $dsn =~ /mysql/i;

eval "require DBI" or die "DBI module not installed. Cannot continue.";

my $database = DBI->connect($dsn) 
    or die "Error: Could not open users database, please check your credentials.\n" . DBI->errstr;
my $type = $database->{Driver}->{Name};

my $autoincrement = $type =~ /mysql/i  ? 'auto_increment'
                   :$type =~ /sqlite/i ? 'autoincrement'
                   :'';
my $last_id       = $type =~ /mysql/i  ? 'mysql_insertid'
                   :$type =~ /sqlite/i ? 'last_insert_rowid'
                   :'';

# Database schema. To change the schema, update/add the fields here, and run this script.
my $users_columns = {
    userid      => "integer PRIMARY KEY $autoincrement",
    email       => "varchar(64) not null UNIQUE",
    pass        => "varchar(44) not null",
    gecos       => "varchar(64)",
    remember    => "boolean not null",
    openid_only => "boolean not null",
    confirmed   => "boolean not null",
    cnfrm_code  => "varchar(32) not null",
    last_login  => "timestamp not null",
    created     => "datetime not null"
};

my $session_columns = {
    userid      => "integer PRIMARY KEY $autoincrement",
    username    => "varchar(32)",
    sessionid   => 'char(32) not null UNIQUE',
    uploadsid   => 'char(32) not null UNIQUE',
};

my $openid_columns = {
    userid     => "integer not null",
    openid_url => "varchar(128) PRIMARY KEY"
};

my $uploads_columns = {
    trackid           => "varchar(32) not null PRIMARY key",
    userid            => "integer not null",
    path              => "text",
    title             => "text",
    description       => "text",
    imported          => "boolean not null",
    creation_date     => "datetime not null",
    modification_date => "datetime",
    sharing_policy    => "ENUM('private', 'public', 'group', 'casual') not null",
    public_count      => "int",
    data_source       => "text",
};

my $sharing_columns = {
    trackid => "varchar(32) not null",
    userid  => "integer not null",
    public  => "boolean",
};

my $dbinfo_columns = {
    schema_version    => 'int(10) not null UNIQUE'
};

my $old_users_columns = {



( run in 1.890 second using v1.01-cache-2.11-cpan-aadc1410aed )