From 379f6269686abe5612a1bf1d0bded8ac96a9e167 Mon Sep 17 00:00:00 2001 From: steve-fischer-200 Date: Wed, 13 Dec 2023 15:04:34 -0500 Subject: [PATCH] write installVdiSchema logs to STDOUT; debug bulkInstallVdiSchema; add .gitignore --- .gitignore | 2 ++ bin/bulkInstallVdiSchema | 15 +++++++++++---- bin/installVdiSchema | 21 +++++++++++---------- 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ca7e92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lib/perl/SchemaInstallUtils.pm + diff --git a/bin/bulkInstallVdiSchema b/bin/bulkInstallVdiSchema index 79ed721..d7f632b 100755 --- a/bin/bulkInstallVdiSchema +++ b/bin/bulkInstallVdiSchema @@ -54,13 +54,20 @@ foreach my $d (@dbDescriptors) { my $flag = $create? '--create' : '--drop'; +if ($drop) { + print "\nYou are about to UNINSTALL the VDI_DATASETS and VDI_CONTROL schemas on database:\n $dbDescriptorsStr\nType 'I am not afraid' to proceed: "; + my $confirm = ; + chomp $confirm; + die "You did not correctly confirm the db instance\n" unless 'I am not afraid' eq $confirm; +} + foreach my $d (@dbDescrips) { foreach my $lifecycle (@lifecycles) { foreach my $campus (@campuses) { - my $cmd = cwd() . "/installVdiSchema --dbName $d->{name} --dbHost $d->{host}.penn.apidb.org $flag --lifecycle $lifecycle --campus $campus"; - $cmd = "$cmd 2>> $logFile"; - print STDERR "Running cmd: $cmd\n"; -# system("$cmd 2> $logFile") && print STDERR "Failed: $!\n"; + my $cmd = cwd() . "/installVdiSchema --dbName $d->{name} --dbHost $d->{host}.penn.apidb.org $flag --lifecycle $lifecycle --campus $campus --dontAsk"; + $cmd = "$cmd >> $logFile"; + print STDERR "\nRunning cmd: $cmd\n"; + system($cmd) && print STDERR "Failed: $!\n"; } } } diff --git a/bin/installVdiSchema b/bin/installVdiSchema index a9612d7..4ffa414 100755 --- a/bin/installVdiSchema +++ b/bin/installVdiSchema @@ -12,7 +12,7 @@ $| = 1; # flush each line on output my @envVars = ('DB_PLATFORM', 'DB_USER', 'DB_PASS'); my $envStr = '$' . join(", \$", @envVars); -my ($dbName, $dbHost, $drop, $create, $lifecycle, $campus, $allowFailures); +my ($dbName, $dbHost, $drop, $create, $lifecycle, $campus, $allowFailures, $dontAsk); &GetOptions("dbName=s" => \$dbName, "dbHost=s" => \$dbHost, @@ -20,7 +20,8 @@ my ($dbName, $dbHost, $drop, $create, $lifecycle, $campus, $allowFailures); "create!" => \$create, "drop!" => \$drop, "lifecycle=s" => \$lifecycle, - "campus=s" => \$campus); + "campus=s" => \$campus, + "dontAsk!" => \$dontAsk); my @lifecycle = ('dev', 'qa', 'feat', 'beta', 'prod'); my $lcStr = join(", ", @lifecycle); @@ -47,7 +48,7 @@ Caution: only use --allowFailures if you know what you are doing Required environment variables: $envStr -Log is printed to STDERR +Log is printed to STDOUT Include the following in your bash environment or on the command line preceding the command below: export DB_PLATFORM=Oracle; export DB_USER=MY-LOGIN; export DB_PASS=MY-PASSWORD; @@ -66,7 +67,7 @@ die "DB Platform must be either 'Oracle' or 'Postgres'\n" unless ($dbVendor eq ' my $dbh = getDbh($dbName, $dbHost, $dbVendor, $login, $password); my $schemaSuffix = uc("${lifecycle}_${campus}"); -if ($drop) { +if ($drop && !$dontAsk) { print "\nYou are about to UNINSTALL the VDI_DATASETS_$schemaSuffix and VDI_CONTROL_$schemaSuffix schemas on database:\n $dbName\nType the name of the database to confirm: "; my $confirm = ; chomp $confirm; @@ -81,9 +82,9 @@ my @create = qw( if ($create) { for my $sqlFile (@create) { - print STDERR "\n==============================================================\n"; - print STDERR "running $sqlFile for $schemaSuffix\n"; - print STDERR "==============================================================\n"; + print STDOUT "\n==============================================================\n"; + print STDOUT "running $sqlFile for $schemaSuffix\n"; + print STDOUT "==============================================================\n"; my @sqlplusParamValues = ($schemaSuffix); my $filePath = cwd() . "/../lib/sql/$dbVendor/$sqlFile"; runSql($login, $password, $dbh, $dbVendor, $filePath, $allowFailures, @sqlplusParamValues); @@ -93,11 +94,11 @@ if ($create) { if ($dbVendor eq 'Oracle') { my $schemaSetStr = join ', ', map "'$_'", @schemas; my $count = dropSchemaSetTables($dbh, $schemaSetStr); - print STDERR "Dropped $count objects\n"; + print STDOUT "Dropped $count objects\n"; } else { my $count = dropSchemaSetPostgres($dbh, @schemas); - print STDERR "Dropped $count schemas\n"; + print STDOUT "Dropped $count schemas\n"; } } -print STDERR "\nDone.\n"; +print STDOUT "\nDone.\n";