]> git.donarmstrong.com Git - debbugs.git/blobdiff - bin/debbugs-installsql
allow debbugs-installsql to take a --dsn option
[debbugs.git] / bin / debbugs-installsql
index 317b2723ce152f607963546259dae92d182361ed..5957acbe536cf83b228fe1335c5de7464a3b3e52 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,
@@ -82,6 +83,7 @@ my %options = (debug           => 0,
 
 GetOptions(\%options,
            'service|s=s',
+          'dsn=s',
            'sysconfdir|c=s',
            'install',
            'install_version_storage|install-version-storage',
@@ -119,8 +121,14 @@ if (exists $options{sysconfdir}) {
     }
 }
 
+if (not exists $options{dsn} or
+    not defined $options{dsn} or
+    not length $options{dsn}) {
+    $options{dsn} = 'dbi:Pg:service='.$options{service};
+}
+
 
-my $schema = Debbugs::DB->connect('dbi:Pg:service='.$options{service}) or
+my $schema = Debbugs::DB->connect($options{dsn}) or
     die "Unable to connect to database";
 
 
@@ -137,6 +145,20 @@ if ($options{current_version}) {
 } elsif ($options{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_deploy if $options{developer_prepare};
     $dh->prepare_upgrade() if $options{developer_prepare};