2 # debbugs-installsql installs the SQL database using DBIx::Class::DeploymentHandler
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
6 # Copyright 2013-2014 by Don Armstrong <don@donarmstrong.com>.
17 debbugs-installsql - installs the SQL database using DBIx::Class::DeploymentHandler
21 debbugs-installsql [ --upgrade | --install ]
24 --service postgresql service to connect to
25 --sysconfdir postgresql system configuration directory
26 --deployment-dir SQL deployment directory
27 --debug, -d debugging level (Default 0)
28 --help, -h display this help
29 --man, -m display manual
37 Postgresl service to connect to (defaults to debbugs)
41 Postgresql sysconf dir. May also be set using the PGSYSCONFDIR
42 environmental variable (which this option overrides).
44 =item B<--deployment-dir>
46 Deployment directory (defaults to /usr/share/debbugs/sqldeployment)
50 Debug verbosity. (Default 0)
54 Display brief usage information.
72 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
74 my %options = (debug => 0,
77 developer_prepare => 0,
78 overwrite_deployment => 0,
80 deployment_dir => '/usr/share/debbugs/sqldeployment',
87 'install_version_storage|install-version-storage',
89 'current_version|current-version',
90 # 'developer_prepare|developer-prepare',
91 'overwrite_deployment|overwrite-deployment',
92 'deployment_dir|deployment-dir=s',
93 'debug|d+','help|h|?','man|m');
95 pod2usage() if $options{help};
96 pod2usage({verbose=>2}) if $options{man};
98 $DEBUG = $options{debug};
102 my @exclusive_options = qw(install upgrade current_version install_version_storage);
103 if (1 < grep {exists $options{$_}} @exclusive_options) {
104 push @USAGE_ERRORS,"You must only give one of the ".
105 join(', ',map {s/_/-/g; "--".$_} @exclusive_options).
108 if (not grep {exists $options{$_}} @exclusive_options) {
109 $options{current_version} = 1;
112 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
114 if (exists $options{sysconfdir}) {
115 if (not defined $options{sysconfdir} or not length $options{sysconfdir}) {
116 delete $ENV{PGSYSCONFDIR};
118 $ENV{PGSYSCONFDIR} = $options{sysconfdir};
123 my $schema = Debbugs::DB->connect('dbi:Pg:service='.$options{service}) or
124 die "Unable to connect to database";
127 my $dh = DH->new({schema => $schema,
128 force_overwrite => $options{overwrite_deployment},
129 script_directory => $options{deployment_dir},
130 databases => 'PostgreSQL'
133 if ($options{current_version}) {
134 print "The current database version is: ".$dh->database_version."\n";
136 } elsif ($options{install}) {
137 $dh->prepare_install;
139 } elsif ($options{upgrade}) {
142 } elsif ($options{install_version_storage}) {
143 $dh->prepare_version_storage_install;
144 $dh->install_version_storage;