From 04413e5c070d44f345718351eb5df10dc79f7b7a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 4 Dec 2015 13:22:54 -0500 Subject: [PATCH] LP#1521693 Integrate sqitch into schema builder script eg_db_config now builds the DB from the Sqitch instance. Signed-off-by: Bill Erickson --- .../src/sql/schema/deploy/create_extensions.sql | 12 ----- .../src/sql/schema/revert/create_extensions.sql | 12 ----- Open-ILS/src/sql/schema/sqitch.plan | 3 +- .../schema/tools/create_database_extensions.sql | 22 ++++++++ .../src/sql/schema/verify/create_extensions.sql | 7 --- Open-ILS/src/support-scripts/eg_db_config.in | 60 ++++++++++++---------- 6 files changed, 55 insertions(+), 61 deletions(-) delete mode 100644 Open-ILS/src/sql/schema/deploy/create_extensions.sql delete mode 100644 Open-ILS/src/sql/schema/revert/create_extensions.sql create mode 100644 Open-ILS/src/sql/schema/tools/create_database_extensions.sql delete mode 100644 Open-ILS/src/sql/schema/verify/create_extensions.sql diff --git a/Open-ILS/src/sql/schema/deploy/create_extensions.sql b/Open-ILS/src/sql/schema/deploy/create_extensions.sql deleted file mode 100644 index b8266af665..0000000000 --- a/Open-ILS/src/sql/schema/deploy/create_extensions.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Deploy evergreen:create_extensions to pg - -BEGIN; - -CREATE LANGUAGE plperlu; - -CREATE EXTENSION tablefunc; -CREATE EXTENSION xml2; -CREATE EXTENSION hstore; -CREATE EXTENSION intarray; - -COMMIT; diff --git a/Open-ILS/src/sql/schema/revert/create_extensions.sql b/Open-ILS/src/sql/schema/revert/create_extensions.sql deleted file mode 100644 index 5f901e93d4..0000000000 --- a/Open-ILS/src/sql/schema/revert/create_extensions.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Revert evergreen:create_extensions from pg - -BEGIN; - -DROP LANGUAGE plperlu; - -DROP EXTENSION tablefunc; -DROP EXTENSION xml2; -DROP EXTENSION hstore; -DROP EXTENSION intarray; - -COMMIT; diff --git a/Open-ILS/src/sql/schema/sqitch.plan b/Open-ILS/src/sql/schema/sqitch.plan index 3a4a1ac314..93a3955f75 100644 --- a/Open-ILS/src/sql/schema/sqitch.plan +++ b/Open-ILS/src/sql/schema/sqitch.plan @@ -2,8 +2,7 @@ %project=evergreen %uri=http://evergreen-ils.org/ -create_extensions 2015-07-16T20:02:22Z Bill Erickson # Start with extensions -functions.general [create_extensions] 2015-07-16T20:40:02Z Bill Erickson # Creating functions.general +functions.general 2015-07-16T20:40:02Z Bill Erickson # Creating functions.general fts-config.english [functions.general] 2015-07-16T20:40:02Z Bill Erickson # Creating fts-config.english schema.offline [fts-config.english] 2015-07-16T20:40:03Z Bill Erickson # Creating schema.offline schema.config [schema.offline] 2015-07-16T20:40:03Z Bill Erickson # Creating schema.config diff --git a/Open-ILS/src/sql/schema/tools/create_database_extensions.sql b/Open-ILS/src/sql/schema/tools/create_database_extensions.sql new file mode 100644 index 0000000000..b73a87168e --- /dev/null +++ b/Open-ILS/src/sql/schema/tools/create_database_extensions.sql @@ -0,0 +1,22 @@ +-- This file is intended to be called by eg_db_config.pl + +-- If manually calling: +-- Connect to the postgres database initially +-- Specify the database to create as -vdb_name=DATABASE +-- Specify the postgres contrib directory as -vcontrib_dir=CONTRIBDIR +-- You can get the contrib directory using pg_config --sharedir and adding a /contrib to it + +-- NOTE: This file does not do transactions +-- This is intentional. Please do not wrap in BEGIN/COMMIT. +DROP DATABASE IF EXISTS :db_name; + +CREATE DATABASE :db_name TEMPLATE template0 ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C'; + +\connect :db_name + +CREATE LANGUAGE plperlu; + +CREATE EXTENSION tablefunc; +CREATE EXTENSION xml2; +CREATE EXTENSION hstore; +CREATE EXTENSION intarray; diff --git a/Open-ILS/src/sql/schema/verify/create_extensions.sql b/Open-ILS/src/sql/schema/verify/create_extensions.sql deleted file mode 100644 index 90ccce01d6..0000000000 --- a/Open-ILS/src/sql/schema/verify/create_extensions.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Verify evergreen:create_extensions on pg - -BEGIN; - --- XXX Add verifications here. - -ROLLBACK; diff --git a/Open-ILS/src/support-scripts/eg_db_config.in b/Open-ILS/src/support-scripts/eg_db_config.in index b59d044b86..de79a7904d 100755 --- a/Open-ILS/src/support-scripts/eg_db_config.in +++ b/Open-ILS/src/support-scripts/eg_db_config.in @@ -28,7 +28,7 @@ use Cwd qw/abs_path getcwd/; my ($dbhost, $dbport, $dbname, $dbuser, $dbpw, $help, $admin_user, $admin_pw, $load_all, $load_concerto); my $config_file = ''; -my $build_db_sh = ''; +my $schema_dir = ''; my $offline_file = ''; my $prefix = ''; my $sysconfdir = ''; @@ -45,9 +45,7 @@ my $cwd = getcwd(); 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'; +my $_sample_dir = abs_path(File::Spec->catdir($script_dir, '../sql/test-data/')); =over @@ -176,17 +174,31 @@ sub create_database { } } -=item create_schema() - Creates the database schema by calling build-db.sh +=item sqitch_deploy() - Execute sqitch deployment script in current directory. =cut -sub create_schema { + +sub sqitch_deploy { my $settings = shift; + $ENV{PGPASSWORD} = $settings->{pw}; + + my $cmd = sprintf( + 'sqitch --db-host %s --db-port %s --db-name %s --db-user %s deploy', + $settings->{host}, $settings->{port}, + $settings->{db}, $settings->{user} + ); + + # assumes non-verbose mode + $cmd = "$cmd 2>&1 | grep -v NOTICE | grep -v '^INSERT'"; - chdir(dirname($build_db_sh)); - my $cmd = File::Spec->catfile('.', basename($build_db_sh)) . " " . - $settings->{host} ." ". $settings->{port} ." ". - $settings->{db} ." ". $settings->{user} ." ". - $settings->{pw}; system($cmd); +} + +=item create_schema() - Creates the database schema by calling build-db.sh +=cut +sub create_schema { + my $settings = shift; + chdir($schema_dir); + sqitch_deploy($settings); chdir($script_dir); } @@ -194,19 +206,10 @@ sub create_schema { =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; + # TODO: support load $load_concerto -- does anyone use it? + # To do this, --log-only load most of the sample data. + sqitch_deploy($settings); chdir($cwd); } @@ -266,7 +269,7 @@ GetOptions("create-schema" => \$cschema, "create-offline" => \$offline, "update-config" => \$uconfig, "config-file=s" => \$config_file, - "build-db-file=s" => \$build_db_sh, + "schema-dir=s" => \$schema_dir, "pg-contrib-dir=s" => \$pg_contribdir, "create-db-sql-contribs=s" => \$create_db_sql_contribs, "create-db-sql-extensions=s" => \$create_db_sql_extensions, @@ -301,8 +304,8 @@ if (!$prefix) { $prefix = $temp[0]; } -if (!$build_db_sh) { - $build_db_sh = File::Spec->catfile($script_dir, '../sql/Pg/build-db.sh'); +if (!$schema_dir) { + $schema_dir = File::Spec->catdir($script_dir, '../sql/schema/'); } if (!$pg_contribdir) { @@ -317,14 +320,15 @@ if (!$create_db_sql_contribs) { } if (!$create_db_sql_extensions) { - $create_db_sql_extensions = File::Spec->catfile($script_dir, '../sql/Pg/create_database_extensions.sql'); + $create_db_sql_extensions = File::Spec->catfile($script_dir, + '../sql/schema/tools/create_database_extensions.sql'); } if (!$offline_file) { $offline_file = File::Spec->catfile($sysconfdir, 'offline-config.pl'); } -unless (-e $build_db_sh) { die "Error: $build_db_sh does not exist. \n"; } +unless (-e $schema_dir) { die "Error: $schema_dir does not exist. \n"; } unless (-e $config_file) { die "Error: $config_file does not exist. \n"; } if ($uconfig) { update_config(\@services, \%settings); } -- 2.11.0