]> git.donarmstrong.com Git - debbugs.git/blobdiff - bin/debbugs-installsql
fix POD failures in DB::Load
[debbugs.git] / bin / debbugs-installsql
index 71beb8d2741a20cd8c06ef16fbccc16483274d66..892aef4b10107eeebab39b0e192440f7fa9dada9 100755 (executable)
@@ -69,6 +69,7 @@ debbugs-installsql
 use vars qw($DEBUG);
 
 use Debbugs::DB;
+use Debbugs::DB::Util qw(prepare_execute);
 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
 
 my %options = (debug           => 0,
@@ -84,10 +85,11 @@ GetOptions(\%options,
            'service|s=s',
            'sysconfdir|c=s',
            'install',
+           'install_version_storage|install-version-storage',
            'upgrade',
            'current_version|current-version',
            'developer_prepare|developer-prepare',
-           'overwrite_deployment|overwrite-deployment',
+           'overwrite_deployment|overwrite-deployment|force_overwrite|force-overwrite',
            'deployment_dir|deployment-dir=s',
           'debug|d+','help|h|?','man|m');
 
@@ -98,7 +100,7 @@ $DEBUG = $options{debug};
 
 my @USAGE_ERRORS;
 
-my @exclusive_options = qw(install upgrade current_version);
+my @exclusive_options = qw(install upgrade current_version install_version_storage);
 if (1 < grep {exists $options{$_}} @exclusive_options) {
       push @USAGE_ERRORS,"You must only give one of the ".
           join(', ',map {s/_/-/g; "--".$_} @exclusive_options).
@@ -126,22 +128,37 @@ my $schema = Debbugs::DB->connect('dbi:Pg:service='.$options{service}) or
 my $dh = DH->new({schema => $schema,
                   force_overwrite => $options{overwrite_deployment},
                   script_directory => $options{deployment_dir},
-                  databases => 'PostgreSQL'
+                  databases => 'PostgreSQL',
+                 sql_translator_args => {producer_args=> {postgres_version => 9}},
                  });
 
 if ($options{current_version}) {
     print "The current database version is: ".$dh->database_version."\n";
     exit 0;
 } elsif ($options{install}) {
-    if ($options{developer_prepare}) {
-        $dh->prepare_install;
-        $dh->prepare_deploy;
-    } else {
-        $dh->install;
-    }
+    $dh->prepare_install if $options{developer_prepare};
+    $dh->install unless $options{developer_prepare};
+    ## this is lame, but because the current release of DeploymentHandler does
+    ## not support WHERE or quoted indexes properly (fixed in git), we create
+    ## these indexes manually here.
+    $schema->storage->
+       dbh_do(sub{my ($s,$dbh) = @_;
+                  prepare_execute($dbh,<<SQL);
+CREATE UNIQUE INDEX bug_status_cache_bug_col_suite_col_arch_idx ON
+ bug_status_cache(bug,COALESCE(suite,0),COALESCE(arch,0));
+CREATE UNIQUE INDEX bug_status_cache_bug_suite_idx ON
+ bug_status_cache(bug,suite) WHERE arch is NULL;
+CREATE UNIQUE INDEX bug_status_cache_bug_idx ON
+ bug_status_cache(bug) WHERE arch is NULL AND suite IS NULL;
+SQL
+                  });
 } elsif ($options{upgrade}) {
-    $dh->prepare_upgrade;
-    $dh->upgrade;
+    $dh->prepare_deploy if $options{developer_prepare};
+    $dh->prepare_upgrade() if $options{developer_prepare};
+    $dh->upgrade unless $options{developer_prepare};
+} elsif ($options{install_version_storage}) {
+    $dh->prepare_version_storage_install if $options{developer_prepare};
+    $dh->install_version_storage unless $options{developer_prepare};
 }