From 8d8372f2fbd8e6c15ec4f4bb19d9deaaaaa18dc4 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Sun, 11 Nov 2012 18:32:44 -0500 Subject: [PATCH] Sample data: enable loading via eg_db_config.pl Add "--load-concerto-sample" and "--load-all-sample" options to the eg_db_config.pl script so that would-be testers can create the database and load sample data on it in one easy step. Add a release notes entry. Signed-off-by: Dan Scott Signed-off-by: Bill Erickson --- Open-ILS/src/support-scripts/eg_db_config.pl | 47 +++++++++++++++++++++++-- docs/RELEASE_NOTES_NEXT/loading_sample_data.txt | 24 +++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 docs/RELEASE_NOTES_NEXT/loading_sample_data.txt diff --git a/Open-ILS/src/support-scripts/eg_db_config.pl b/Open-ILS/src/support-scripts/eg_db_config.pl index e98710f331..665cedf348 100755 --- a/Open-ILS/src/support-scripts/eg_db_config.pl +++ b/Open-ILS/src/support-scripts/eg_db_config.pl @@ -24,8 +24,9 @@ use Getopt::Long; use File::Spec; use File::Basename; use DBI; +use Cwd qw/abs_path getcwd/; -my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help, $admin_user, $admin_pw); +my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help, $admin_user, $admin_pw, $load_all, $load_concerto); my $config_file = ''; my $build_db_sh = ''; my $offline_file = ''; @@ -38,8 +39,15 @@ my @services; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +my $cwd = getcwd(); + # Get the directory for this script -my $script_dir = dirname($0); +my $script_dir = abs_path(dirname($0)); + +# Set the location and base file for sample data +my $_sample_dir = abs_path(File::Spec->catdir($script_dir, '../../tests/datasets/sql/')); +my $_sample_all = 'load_all.sql'; +my $_sample_concerto = 'load_concerto.sql'; =over @@ -182,6 +190,26 @@ sub create_schema { chdir($script_dir); } +=item load_sample_data() - Loads sample bib records, copies, users, and transactions +=cut +sub load_sample_data { + my $settings = shift; + + my $load_script = $_sample_all; + chdir($_sample_dir); + if ($load_concerto) { + $load_script = $_sample_concerto; + } + $ENV{'PGUSER'} = $settings->{user}; + $ENV{'PGPASSWORD'} = $settings->{pw}; + $ENV{'PGPORT'} = $settings->{port}; + $ENV{'PGHOST'} = $settings->{host}; + $ENV{'PGDATABASE'} = $settings->{db}; + my @output = `psql -f $load_script 2>&1`; + print @output; + chdir($cwd); +} + =item set_admin_account() - Sets the administrative user's user name and password =cut sub set_admin_account { @@ -216,6 +244,8 @@ my %settings; GetOptions("create-schema" => \$cschema, "create-database" => \$cdatabase, + "load-all-sample" => \$load_all, + "load-concerto-sample" => \$load_concerto, "create-offline" => \$offline, "update-config" => \$uconfig, "config-file=s" => \$config_file, @@ -290,9 +320,12 @@ if ($cschema) { create_schema(\%settings); } if ($admin_user && $admin_pw) { set_admin_account($admin_user, $admin_pw, \%settings); } +if ($load_all || $load_concerto) { + load_sample_data(\%settings); +} if ($offline) { create_offline_config($offline_file, \%settings); } -if ((!$cdatabase && !$cschema && !$uconfig && !$offline && !$admin_pw) || $help) { +if ((!$cdatabase && !$cschema && !$load_all && !$load_concerto && !$uconfig && !$offline && !$admin_pw) || $help) { print <