X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bin%2Fdebbugs-installsql;h=1ecccb48534799372ef9b5de4241ef2c0f9d7031;hb=01c360c8831df87a69fe1f49a08dda22ded51950;hp=3b29618b244993cb95a7c7922ba18dc1513ade26;hpb=bc655cd0e8a2584c7bd420001c33db9b56dfb7bd;p=debbugs.git diff --git a/bin/debbugs-installsql b/bin/debbugs-installsql index 3b29618..1ecccb4 100755 --- a/bin/debbugs-installsql +++ b/bin/debbugs-installsql @@ -45,6 +45,11 @@ environmental variable (which this option overrides). Deployment directory (defaults to /usr/share/debbugs/sqldeployment) +=item B<--drop> + +Drop tables before trying to create them. (Useful for --install, primarily). +Defaults to not drop tables for safety. + =item B<--debug, -d> Debug verbosity. (Default 0) @@ -68,27 +73,36 @@ debbugs-installsql use vars qw($DEBUG); +# if we're running out of git, we want to use the git base directory as the +# first INC directory. If you're not running out of git, or someone has given a +# non-absolute INC, don't do that. +use FindBin; +use if (-d $FindBin::Bin.'/../.git/' && $INC[0] =~ m#^/#), + lib => $FindBin::Bin.'/../'; + use Debbugs::DB; +use Debbugs::DB::Util qw(prepare_execute); use aliased 'DBIx::Class::DeploymentHandler' => 'DH'; my %options = (debug => 0, help => 0, man => 0, - developer_prepare => 0, overwrite_deployment => 0, + drop => 0, service => 'debbugs', deployment_dir => '/usr/share/debbugs/sqldeployment', ); GetOptions(\%options, 'service|s=s', + 'dsn=s', 'sysconfdir|c=s', 'install', 'install_version_storage|install-version-storage', 'upgrade', + 'drop', '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'); @@ -119,15 +133,24 @@ 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"; 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 => 8.1}, + add_drop_table => $options{drop}, + }, }); if ($options{current_version}) { @@ -136,8 +159,23 @@ if ($options{current_version}) { } elsif ($options{install}) { $dh->prepare_install; $dh->install; + ## 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,<prepare_deploy; + $dh->prepare_upgrade; $dh->upgrade; } elsif ($options{install_version_storage}) { $dh->prepare_version_storage_install;