# This version must be incremented any time the schema changes so that
# DBIx::Class::DeploymentHandler can do its work
-our $VERSION=6;
+our $VERSION=7;
# You can replace this text with custom code or comments, and it will be preserved on regeneration
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-03-04 10:59:03
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dgaCogdpUWo99BQhdH68Mg
+sub sqlt_deploy_hook {
+ my ($self, $sqlt_table) = @_;
+# $sqlt_table->add_index(name => 'bug_status_cache_bug_suite_arch_idx',
+# fields => ['bug',
+# q{COALESCE(suite,0)},
+# q{COALESCE(arch,0)},]
+# );
+ for my $f (qw(bug status arch suite asof)) {
+ $sqlt_table->add_index(name => 'bug_status_cache_idx_'.$f,
+ fields => [$f],
+ );
+ }
+}
-# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
INSERT INTO bug_status_cache AS bsc
(bug,suite,arch,status,modified,asof)
VALUES (?,?,?,?,NOW(),NOW())
-ON CONFLICT (bug,suite,arch) DO
+ON CONFLICT (bug,COALESCE(suite,0),COALESCE(arch,0)) DO
UPDATE
SET asof=NOW(),modified=CASE WHEN bsc.status=? THEN bsc.modified ELSE NOW() END
RETURNING status;
@EXPORT = ();
%EXPORT_TAGS = (select => [qw(select_one)],
+ execute => [qw(prepare_execute)]
);
@EXPORT_OK = ();
Exporter::export_ok_tags(keys %EXPORT_TAGS);
return (ref($results) and ref($results->[0]))?$results->[0][0]:undef;
}
+=item prepare_execute
+
+ prepare_execute($dbh,$sql,@bind_vals)
+
+Prepares and executes a statement
+
+=cut
+
+sub prepare_execute {
+ my ($dbh,$sql,@bind_vals) = @_;
+ my $sth = $dbh->
+ prepare_cached($sql,
+ {dbi_dummy => __FILE__.__LINE__ })
+ or die "Unable to prepare statement: $sql";
+ $sth->execute(@bind_vals) or
+ die "Unable to execute statement: ".$dbh->errstr();
+ $sth->finish();
+}
+
=back
use vars qw($DEBUG);
use Debbugs::DB;
+use Debbugs::DB::Util qw(prepare_execute);
use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
my %options = (debug => 0,
} 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};