#!/usr/bin/perl
## Initialize Rose::DB code given the DB structure

use lib "/opt/testidp/IdPAccountManager/lib";
use lib "/opt/testidp/IdPAccountManager/conf";

use Rose::DB;
use Rose::DB::Object::Loader;
use Getopt::Long;
use Conf;

my %options;
unless (&GetOptions(\%options, 'database=s')) {
    die "Unknown options.";
}

my $dbname = $options{'database'} || $Conf::global{'database_name'};

$loader = 
    Rose::DB::Object::Loader->new(
        db_dsn       => 'dbi:'.$Conf::global{'database_type'}.':dbname='.$dbname.';host='.$Conf::global{'database_host'},
        db_username  => $Conf::global{'database_user'},
        db_password  => $Conf::global{'database_password'},
        db_options   => { AutoCommit => 1, ChopBlanks => 1 },
        class_prefix => 'IdPAccountManager::Data',
        #with_unique_keys => 0,
        );

$loader->make_modules(with_managers => 1,
                      module_dir => '/tmp',
                      #with_relationships => ['one to many','many to one']
    );

printf "Database-related code created in /tmp/IdPAccountManager. You should copy this code in lib/ directory\n";