From: Dan Scott <dscott@laurentian.ca>
Date: Sun, 11 Nov 2012 23:32:44 +0000 (-0500)
Subject: Sample data: enable loading via eg_db_config.pl
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8d8372f2fbd8e6c15ec4f4bb19d9deaaaaa18dc4;p=evergreen%2Fmasslnc.git

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 <dscott@laurentian.ca>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
---

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 <<HERE;
 
 SYNOPSIS
@@ -332,6 +365,14 @@ COMMANDS
         Creates the database itself, provided the user and password options
         represent a superuser.
 
+    --load-all-sample
+		Loads all sample data, including bibliographic records, call numbers,
+		copies, users, and transactions.
+
+    --load-concerto-sample
+		Loads a subset of sample data that includes just 100 bibliographic
+		records, and associated call numbers and copies.
+
 SERVICE OPTIONS
     --service
         Specify "all" or one or more of the following services to update:
diff --git a/docs/RELEASE_NOTES_NEXT/loading_sample_data.txt b/docs/RELEASE_NOTES_NEXT/loading_sample_data.txt
new file mode 100644
index 0000000000..063eb1e2f6
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/loading_sample_data.txt
@@ -0,0 +1,24 @@
+New feature: loading sample data
+================================
+One common need for people evaluating Evergreen, as well as for developers,
+writers, and testers, is a set of sample data that can be easily loaded into
+the Evergreen database and provide a consistent set of results for testing
+and training purposes.
+
+This release features sets of sample data consisting of:
+
+* 100 bibliographic records retrievable via a "concerto" keyword search
+* 100 French bibliographic records
+* Associated call numbers, copies, parts, and conjoined items
+* Patron accounts, including some recently expired patrons
+* Circulation transactions, including some holds and some overdue items
+
+To load the sample data into a freshly installed Evergreen database, you can
+pass the following arguments to the `eg_db_config` script (either when you are
+creating the initial database schema, or as a separate call after creating the
+database schema):
+
+* `--load-all-sample`: Loads all sample data, including bibliographic records,
+   call numbers, copies, users, and transactions.
+* `--load-concerto-sample`: Loads a subset of sample data that includes just
+  100 bibliographic records, and associated call numbers and copies.