bug 8798: (follow-up) pass DB connection params to DBIC schema updater explicitly
authorGalen Charlton <gmc@esilibrary.com>
Mon, 14 Oct 2013 20:57:24 +0000 (20:57 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 14 Oct 2013 21:08:03 +0000 (21:08 +0000)
This patch changes update_dbix_class_files.pl so that the connection
parameters to the reference database must be passed explicitly via
command-line switches, rather than grabbing them from the current Koha
context.

The purpose of this is to intentionally put up a roadblock to reduce
the chance that a developer (or release manager) accidentally updates
the schema files to include local testing cruft such as temporary
tables.

Usage is now as follows:

[1] Create an empty database
[2] Load the schema creation script into it, e.g.,

mysql -u dbic -pdbic dbic < installer/data/mysql/kohastructure.sql

[3] Run the schema updater:

./misc/devel/update_dbix_class_files.pl --db_user=dbic --db_name=dbic --db_passwd=dbic

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
misc/devel/update_dbix_class_files.pl

index 83ac357..08c0170 100755 (executable)
@@ -1,28 +1,46 @@
 #!/usr/bin/perl
 
-use strict;
-use warnings;
-use C4::Context;
+# This file is part of Koha.
+#
+# Copyright (C) 2012 ByWater Solutions
+# Copyright (C) 2013 Equinox Software, Inc.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
 use Getopt::Long;
 
 my $path = "./";
+my $db_driver = 'mysql';
+my $db_host = 'localhost';
+my $db_port = '3306';
+my $db_name = '';
+my $db_user = '';
+my $db_passwd = '';
 GetOptions(
-    "path=s" => \$path,
-    );
-my $context = new C4::Context;
-my $db_driver;
-if ($context->config("db_scheme")){
-    $db_driver=C4::Context->db_scheme2dbi($context->config("db_scheme"));
-}else{
-    $db_driver="mysql";
-}
-
-
-my $db_name   = $context->config("database");
-my $db_host   = $context->config("hostname");
-my $db_port   = $context->config("port") || '';
-my $db_user   = $context->config("user");
-my $db_passwd = $context->config("pass");
+    "path=s"      => \$path,
+    "db_driver=s" => \$db_driver,
+    "db_host=s"   => \$db_host,
+    "db_port=s"   => \$db_port,
+    "db_name=s"   => \$db_name,
+    "db_user=s"   => \$db_user,
+    "db_passwd=s" => \$db_passwd,
+);
 
-make_schema_at("Koha::Schema", {debug => 1, dump_directory => $path}, ["DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",$db_user, $db_passwd ]);
+make_schema_at(
+    "Koha::Schema",
+    {debug => 1, dump_directory => $path},
+    ["DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",$db_user, $db_passwd ]
+);